public ActionResult Edit(FormCollection formCollection, [FetchStore(KeyName = "id")]StoreEntity entity, StoreViewModel vo) { if (entity == null || !ModelState.IsValid) { ModelState.AddModelError("", "参数验证失败."); return View(vo); } entity.GpsAlt = vo.GpsAlt; entity.GpsLat = vo.GpsLat; entity.GpsLng = vo.GpsLng; entity.Latitude = vo.Latitude; entity.Longitude = vo.Longitude; entity.Name = vo.Name; entity.Tel = vo.Tel; entity.Description = vo.Description; entity.Longitude = vo.Longitude; entity.UpdatedDate = DateTime.Now; entity.UpdatedUser = CurrentUser.CustomerId; using (TransactionScope ts = new TransactionScope()) { this._storeRepository.Update(entity); if (ControllerContext.HttpContext.Request.Files.Count > 0) { foreach (string fileName in ControllerContext.HttpContext.Request.Files) { var file = ControllerContext.HttpContext.Request.Files[fileName]; if (file == null || file.ContentLength == 0) continue; //remove existing resource var resourceParts = fileName.Split('_'); if (resourceParts.Length > 1) { int resourceId = int.Parse(resourceParts[1]); _resouceService.Del(resourceId); } } //add new resource _resouceService.Save(ControllerContext.HttpContext.Request.Files , CurrentUser.CustomerId , -1, entity.Id , SourceType.StoreLogo); } ts.Complete(); } return RedirectToAction("details",new {id=entity.Id}); }
public ActionResult Details(int? id, [FetchStore(KeyName = "id")]StoreEntity entity) { if (id == null || entity == null) { ModelState.AddModelError("", "参数验证失败."); return View(); } var vo = new StoreViewModel().FromEntity<StoreViewModel>(entity ,model=>model.Resources=new ResourceViewModel().FromEntities<ResourceViewModel>( _resourceRepo.Get(r=>r.SourceId==model.Id && r.SourceType == (int)SourceType.StoreLogo).ToList()) ); return View(vo); }
public ActionResult Create(FormCollection formCollection, StoreViewModel vo) { if (ModelState.IsValid) { var entity = MappingManager.StoreEntityMapping(vo); entity.CreatedUser = base.CurrentUser.CustomerId; entity.UpdatedDate = DateTime.Now; entity.UpdatedUser = base.CurrentUser.CustomerId; entity.Status = (int)DataStatus.Normal; using (var ts = new TransactionScope()) { entity = this._storeRepository.Insert(entity); if (ControllerContext.HttpContext.Request.Files.Count > 0) { _resouceService.Save(ControllerContext.HttpContext.Request.Files , entity.CreatedUser , 0 , entity.Id , SourceType.StoreLogo); } ts.Complete(); } return RedirectToAction("Edit",new {id=entity.Id}); } return View(vo); }