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 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 ExecuteResult <PromotionInfoResponse> DestroyResourcePromotion(DestroyResourcePromotionRequest request) { if (request == null) { return(new ExecuteResult <PromotionInfoResponse>(null) { StatusCode = StatusCode.ClientError, Message = "参数错误" }); } var entity = _promotionRepository.GetItem(request.PromotionId); if (entity == null) { return(new ExecuteResult <PromotionInfoResponse>(null) { StatusCode = StatusCode.ClientError, Message = "参数错误,没有找到指定promotion" }); } var resources = _resourceService.Get(entity.Id, SourceType.Promotion); if (resources == null || resources.Count == 0) { return(new ExecuteResult <PromotionInfoResponse>(null) { StatusCode = StatusCode.ClientError, Message = "参数错误,没有找到promotion的资源" }); } var resouce = resources.SingleOrDefault(v => v.Id == request.ResourceId); if (resouce == null) { return(new ExecuteResult <PromotionInfoResponse>(null) { StatusCode = StatusCode.ClientError, Message = "参数错误,没有找到promotion的指定资源" }); } _resourceService.Del(resouce.Id); entity.UpdatedDate = DateTime.Now; entity.UpdatedUser = request.AuthUid; _promotionRepository.Update(entity); return(new ExecuteResult <PromotionInfoResponse>(MappingManager.PromotionResponseMapping(entity))); }
public ActionResult Edit(FormCollection formCollection, BannerViewModel vo) { var entity = _bannerRepo.GetItem(vo.Id); if (!ModelState.IsValid || entity == null) { ModelState.AddModelError("", "参数验证失败."); return(View(vo)); } entity.UpdatedDate = DateTime.Now; entity.UpdatedUser = base.CurrentUser.CustomerId; entity.Status = vo.Status; entity.SortOrder = vo.SortOrder; entity.SourceId = vo.SourceId; using (TransactionScope ts = new TransactionScope()) { _bannerRepo.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]); _resourceSer.Del(resourceId); } } //add new resource _resourceSer.Save(ControllerContext.HttpContext.Request.Files , CurrentUser.CustomerId , -1, entity.Id , SourceType.BannerPromotion); } ts.Complete(); } return(RedirectToAction("Details", new { id = entity.Id })); }
public ActionResult Edit(FormCollection formCollection, [FetchSpecialTopic(KeyName = "id")] SpecialTopicEntity entity, SpecialTopicViewModel vo) { if (entity == null || !ModelState.IsValid) { ModelState.AddModelError("", "参数验证失败."); return(View(vo)); } var newEntity = MappingManager.SpecialTopicEntityMapping(vo); newEntity.CreatedUser = entity.CreatedUser; newEntity.CreatedDate = entity.CreatedDate; newEntity.UpdatedDate = DateTime.Now; newEntity.UpdatedUser = base.CurrentUser.CustomerId; MappingManager.SpecialTopicEntityMapping(newEntity, entity); using (TransactionScope ts = new TransactionScope()) { this._specialTopicRepository.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]); _resourceRepository.Del(resourceId); } } //add new resource _resourceRepository.Save(ControllerContext.HttpContext.Request.Files , CurrentUser.CustomerId , -1, entity.Id , SourceType.SpecialTopic); } ts.Complete(); } return(RedirectToAction("List")); }
public ActionResult Edit(FormCollection formCollection, [FetchBrand(KeyName = "id")] BrandEntity entity, BrandViewModel vo) { if (entity == null || !ModelState.IsValid) { ModelState.AddModelError("", "参数验证失败."); return(View(vo)); } entity.Name = vo.Name; entity.Group = vo.Group; entity.WebSite = vo.WebSite ?? string.Empty; entity.Description = vo.Description ?? string.Empty; entity.EnglishName = vo.EnglishName ?? string.Empty; entity.UpdatedDate = DateTime.Now; entity.UpdatedUser = CurrentUser.CustomerId; using (var ts = new TransactionScope()) { if (ControllerContext.HttpContext.Request.Files.Count > 0) { var oldImage = _resourceRepository.Get(r => r.SourceType == (int)SourceType.BrandLogo && 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.BrandLogo); if (resources != null && resources.Count() > 0) { entity.Logo = resources[0].AbsoluteUrl; } } _brandRepository.Update(entity); ts.Complete(); } return(RedirectToAction("Details", new { id = entity.Id })); }
/// <summary> /// 上传头像 /// </summary> /// <param name="request"></param> /// <returns></returns> public ExecuteResult <CustomerInfoResponse> UploadLogo(UploadLogoRequest request) { //直接替换掉以前的头像,使用新头像 if (request.Files.Count == 0) { return(new ExecuteResult <CustomerInfoResponse>(null) { StatusCode = StatusCode.ClientError, Message = "图像文件不能为空" }); } if (request.Files.Count != 1) { return(new ExecuteResult <CustomerInfoResponse>(null) { StatusCode = StatusCode.ClientError, Message = "您只能上传一张头像" }); } if (!request.Type.HasValue || request.Type.Value == Hangzhou.Contract.DTO.ThumnImageType.Logo) { var oldResource = _resourceService.Get(request.AuthUid, SourceType.CustomerPortrait); var resourceResult = _resourceService.Save(request.Files, request.AuthUid, 0, request.AuthUid, SourceType.CustomerPortrait); if (resourceResult == null || resourceResult.Count == 0) { Logger.Error(String.Format("保存用户LOGO资源文件异常,用户ID={0}", request.AuthUid)); return(new ExecuteResult <CustomerInfoResponse>(null) { StatusCode = StatusCode.InternalServerError, Message = "保存文件异常" }); } if (resourceResult.Count != 1) { Logger.Warn(String.Format("用户上传头像为1张时,返回不止一个资源.用户Id={0},资源Id={1}", request.AuthUid, String.Join(",", resourceResult.Select(v => v.Id).ToArray()))); } //删除旧resource foreach (var item in oldResource) { _resourceService.Del(item.Id); } //update var userentity = _customerRepository.GetItem(request.AuthUid); userentity.Logo = Path.Combine(resourceResult[0].Domain, resourceResult[0].Name); userentity.UpdatedDate = DateTime.Now; userentity.UpdatedUser = request.AuthUser.Id; _customerRepository.Update(userentity); return(GetUserInfo(new GetUserInfoRequest { AuthUid = request.AuthUid, AuthUser = null, Method = null, Token = null, Client_Version = request.Client_Version })); } else { ResourceInfoResponse logoBG = null; using (var ts = new TransactionScope()) { var oldResource = _resourceService.Get(request.AuthUser.Id, SourceType.CustomerThumbBackground).FirstOrDefault(); if (oldResource != null) { _resourceService.Del(oldResource.Id); } var resourceResult = _resourceService.Save(request.Files, request.AuthUser.Id, 0, request.AuthUser.Id, SourceType.CustomerThumbBackground); if (resourceResult == null || resourceResult.Count == 0) { Logger.Error(String.Format("保存用户LOGO资源文件异常,用户ID={0}", request.AuthUser.Id)); return(new ExecuteResult <CustomerInfoResponse>(null) { StatusCode = StatusCode.InternalServerError, Message = "保存文件异常" }); } logoBG = new ResourceInfoResponse().FromEntity <ResourceInfoResponse>(resourceResult.First()); ts.Complete(); } var response = new CustomerInfoResponse() { BackgroundLogo_r = logoBG }; return(new ExecuteResult <CustomerInfoResponse>(response)); } }