public ActionResult Edit(FormCollection formCollection, [FetchUser(KeyName = "id")]UserModel model, CustomerViewModel vo) { if (model == null || !ModelState.IsValid) { ModelState.AddModelError("", "参数验证失败."); return View(vo); } var entity = _customerRepository.GetItem(model.Id); entity.Mobile = vo.Mobile; entity.Name = vo.Name; entity.Nickname = vo.Nickname; if (string.Compare(vo.Password, entity.Password, false) != 0) entity.Password = SecurityHelper.ComputeHash(vo.Password); entity.UpdatedDate = DateTime.Now; entity.UpdatedUser = CurrentUser.CustomerId; entity.UserLevel = vo.UserLevel; entity.Description = vo.Description; entity.EMail = vo.EMail; using (var ts = new TransactionScope()) { if (ControllerContext.HttpContext.Request.Files.Count > 0) { var oldImage = _resourceRepository.Get(r => r.SourceType == (int)SourceType.CustomerPortrait && r.SourceId == entity.Id).FirstOrDefault(); if (oldImage!=null) _resourceService.Del(oldImage.Id); var resources = this._resourceService.Save(ControllerContext.HttpContext.Request.Files , CurrentUser.CustomerId , -1, entity.Id , SourceType.CustomerPortrait); if (resources != null && resources.Count() > 0) { entity.Logo = resources[0].AbsoluteUrl; } } this._customerRepository.Update(entity); ts.Complete(); return RedirectToAction("Details", new { id = entity.Id }); } }
public ActionResult Create(FormCollection formCollection, CustomerViewModel vo) { if (ModelState.IsValid) { var entity = MappingManager.UserEntityMapping(MappingManager.UserModelMapping(vo)); entity.CreatedUser = base.CurrentUser.CustomerId; entity.UpdatedUser = base.CurrentUser.CustomerId; entity.Status = (int)DataStatus.Normal; entity.LastLoginDate = DateTime.Now; entity.Password = SecurityHelper.ComputeHash(entity.Password); using (var ts = new TransactionScope()) { entity = this._customerRepository.Insert(entity); if (ControllerContext.HttpContext.Request.Files.Count > 0) { var resources = this._resourceService.Save(ControllerContext.HttpContext.Request.Files , CurrentUser.CustomerId , -1, entity.Id , SourceType.CustomerPortrait); if (resources != null && resources.Count() > 0) { entity.Logo = resources[0].AbsoluteUrl; _customerRepository.Update(entity); ts.Complete(); return RedirectToAction("Details", new { id = entity.Id }); } } } } return View(vo); }