public ActionResult Edit(AreaCreateDTO req) { Response res = new Response(); if (ModelState.IsValid) { try { if (req.Id > 0) { res.Data = _areaRepository.Update(req); } else { res.Data = _areaRepository.Create(req); } } catch (Exception ex) { res.Message = ex.Message; } } else { res.Data = false; res.Message = string.Join(",", ModelState .SelectMany(ms => ms.Value.Errors) .Select(e => e.ErrorMessage)); } return(Json(res, JsonRequestBehavior.AllowGet)); }
public ActionResult Create(CreateAreaViewModel model) { try { if (!ModelState.IsValid) { return(View(model)); } var Area = _mapper.Map <Area>(model); var isSuccess = _areaRepository.Create(Area); if (!isSuccess) { return(View(model)); } return(RedirectToAction(nameof(Index))); } catch { ModelState.AddModelError("", "در ثبت اطلاعات مشکلی به وجود آمده است"); return(View(model)); } }
public void Create(IEnumerable <AreaDTO> areaDTOs) { var list = new List <Area>(); foreach (var item in areaDTOs) { if (!IsDescriptionUniqueByLayoutId(item)) { throw new NotUniqueDescriptionException(); } list.Add(new Area { LayoutId = item.LayoutId, Description = item.Description, CoordX = item.CoordX, CoordY = item.CoordY }); } repository.Create(list); }
public void CreateArea(Area area, HttpPostedFileBase areaMap) { using (TransactionScope transaction = new TransactionScope(TransactionScopeOption.Required, new TransactionOptions() { IsolationLevel = IsolationLevel.ReadCommitted, Timeout = CommonConfiguration.Configuration.TransactionScope_Timeout })) { _areaRepository.Create(area); area.AssetAreaId = ProcessIncomingImage(area.ClientId, area.CreateUserId.Value, area.AssetAreaId, null, areaMap); if (area.AssetAreaId != null && _areaRepository.UpdateEntity(area) > 0 && area.Id > 0) { transaction.Complete(); } } }
public void UpdateProfile(ProfileEntity profile) { if (profile.Role != "0") { userRepository.AddRoleToUser(roleRepository.GetByPredicate(r => r.Name == profile.Role), userRepository.GetById(profile.Id)); uow.Commit(); } var dalProfile = profileRepository.GetById(profile.Id); dalProfile.DalAreas = new HashSet <DalArea>(); if (profile.Role != "Manager") { foreach (var area in profile.AreaEntities) { var dalArea = areaRepository.GetByPredicate(x => x.Name == area); if (dalArea == null) { areaRepository.Create(new DalArea() { Name = area }); uow.Commit(); profileRepository.AddAreaToProfile(dalProfile, areaRepository.GetByPredicate(x => x.Name == area)); } else { profileRepository.AddAreaToProfile(dalProfile, dalArea); } } } profile.Id = dalProfile.Id; profile.AreaEntities = new HashSet <string>(); profileRepository.Update(profile.ToDalProfile()); uow.Commit(); }