当前位置: 首页>>代码示例>>C#>>正文


C# UserModel.ToEntity方法代码示例

本文整理汇总了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;
        }
开发者ID:sankardevts,项目名称:Ignite,代码行数:27,代码来源:UserController.cs

示例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();
            }
        }
开发者ID:thuyhk,项目名称:ThuanThienVN,代码行数:86,代码来源:UserController.cs

示例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;
 }
开发者ID:sito92,项目名称:Praca-inzynierska,代码行数:22,代码来源:UserService.cs


注:本文中的UserModel.ToEntity方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。