本文整理汇总了C#中UserModel.ToEntity方法的典型用法代码示例。如果您正苦于以下问题:C# UserModel.ToEntity方法的具体用法?C# UserModel.ToEntity怎么用?C# UserModel.ToEntity使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类UserModel
的用法示例。
在下文中一共展示了UserModel.ToEntity方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Post
public HttpResponseMessage Post(UserModel model)
{
HttpResponseMessage response = new HttpResponseMessage();
var user = model.ToEntity();
int userId = userService.UserRegistrationAndUpdation("insert",user);
if (model.Image != null)
{
if (HttpContext.Current.Request.Files.AllKeys.Any())
{
// Get the uploaded image from the Files collection
var httpPostedFile = HttpContext.Current.Request.Files["UploadedImage"];
if (httpPostedFile != null)
{
string lastPart = Path.GetExtension(httpPostedFile.FileName);
string fileName = string.Format("{0}_{1}.{2}", httpPostedFile.FileName, userId, lastPart);
// Get the complete file path
var fileSavePath = Path.Combine(HttpContext.Current.Server.MapPath("~/Images/User"), httpPostedFile.FileName);
// Save the uploaded file to "UploadedFiles" folder
httpPostedFile.SaveAs(fileSavePath);
}
}
}
response.Content = new StringContent("Registration Successfully", Encoding.Unicode);
return response;
}
示例2: Create
public ActionResult Create(UserModel model)
{
try
{
if (ModelState.IsValid)
{
// TODO: Add insert logic here
var roleID = model.RoleId;
string encryptPassword = "";
string passwordSalt = "";
passwordSalt = EncryptProvider.GenerateSalt();
encryptPassword = EncryptProvider.EncryptPassword(model.Password, passwordSalt);
model.CreatedDate = DateTime.Now;
model.ModifiedDate = DateTime.Now;
model.LastLogonDate = DateTime.Now;
model.PasswordSalt = passwordSalt;
model.Password = encryptPassword;
model.IsAdmin = true;
#region upload file image to server
try
{
if (_logoModel != null && !string.IsNullOrEmpty(_logoModel.FileName))
{
model.Image = _logoModel.FileName;
var srcFile = Path.Combine(Server.MapPath(Globals.TempImagePath(_logoModel.FileName)));
var desFile = Path.Combine(Server.MapPath(Globals.ImagePath(ConstantKeys.AvatarFolder, _logoModel.FileName)));
// delete image if exist
IOUtility.DeleteFile(desFile);
// get temp file
string tempFile = Server.MapPath(Globals.TempImagePath(_logoModel.FileName));
// get folder thumbs
string thumbFolder = Server.MapPath(Globals.ThumbPath(ConstantKeys.AvatarFolder, _logoModel.FileName));
// get folder image
string imageFolder = Server.MapPath(Globals.ImagePath(ConstantKeys.AvatarFolder, _logoModel.FileName));
// create thumb image
System.Drawing.Image img = ImageUtility.ScaleImage(tempFile, 208, 180, "#ffffff");
ImageUtility.SaveImage(thumbFolder, img);
img.Dispose();
// create image
img = ImageUtility.ScaleImage(tempFile, 200, 200, "#ffffff");
ImageUtility.SaveImage(imageFolder, img);
img.Dispose();
// delete temp file
IOUtility.DeleteFile(srcFile);
//// move full images
//IOUtility.MoveFile(srcFile, desFile);
}
else
model.Image = "default.jpg";
_logoModel = null;
}
catch (Exception ex)
{
model.Image = "default.jpg";
ex.ToString();
}
#endregion
var _userEntity = model.ToEntity();
_userEntity.ObjectState = ObjectState.Added;
_userService.Insert(_userEntity);
_unitOfWork.SaveChanges();
return RedirectToAction("Index");
}
return View(model);
}
catch
{
return View();
}
}
示例3: Update
public ResponseBase Update(UserModel user)
{
ResponseBase response;
using (var unitOfWork = _unitOfWorkFactory.Create())
{
try
{
if (user != null)
{
unitOfWork.UserRepository.Update(user.ToEntity());
}
unitOfWork.Save();
response = new ResponseBase() { IsSucceed = true, Message = Modules.Resources.Logic.ModifyUserSuccess };
}
catch (Exception e)
{
_logger.LogToFile(_logger.CreateErrorMessage(e));
response = new ResponseBase() { IsSucceed = false, Message = Modules.Resources.Logic.ModifyUserFailed };
}
}
return response;
}