public ActionResult AddEnterpriseInfo(WJ_EnterpriseInfoModel model) { if (model.Id.HasValue) { model.UpdateUser = CurrentUser.Id; } else { model.CreateUser = CurrentUser.Id; } return(Json(new JsonMessage(service.AddEnterpriseInfo(model, Server.MapPath("~"))))); }
public bool AddEnterpriseInfo(WJ_EnterpriseInfoModel model, string rootPath) { using (DataProvider dp = new DataProvider()) { if (model.Id.HasValue) { WJ_EnterpriseInfo entity = dp.WJ_EnterpriseInfo.FirstOrDefault(m => m.Id == model.Id.Value); entity.Title = model.Title; entity.InfoType = model.InfoType; entity.Title = model.Title; entity.InfoTime = model.InfoTime; entity.InfoDesc = model.InfoDesc; entity.Sort = model.Sort; entity.ImageUrl = model.ImageUrl; if (entity.ImageUrl.IsNotNullOrWhiteSpace()) { string newPath = FileHelper.GetNewFile("/Upload/EnterpriseInfoCover/", entity.ImageUrl); FileHelper.CutFile(rootPath + entity.ImageUrl, rootPath + newPath); entity.ImageUrl = newPath; } entity.UpdateTime = DateTime.Now; } else { WJ_EnterpriseInfo entity = Mapper.Map <WJ_EnterpriseInfo>(model); if (entity.ImageUrl.IsNotNullOrWhiteSpace()) { string newPath = FileHelper.GetNewFile("/Upload/EnterpriseInfoCover/", entity.ImageUrl); FileHelper.CutFile(rootPath + entity.ImageUrl, rootPath + newPath); entity.ImageUrl = newPath; } entity.CreateTime = DateTime.Now; dp.WJ_EnterpriseInfo.Add(entity); } try { dp.SaveChanges(); return(true); } catch { return(false); } } }