public async Task <ActualResult> RestructuringUnits(SubdivisionDTO dto) { var checkMainSubdivisions = await _hashIdUtilities.CheckDecryptWithId(dto.HashId, Enums.Services.Subdivision); var checkSubordinateSubdivisions = await _hashIdUtilities.CheckDecryptWithId(dto.HashIdSubordinate, Enums.Services.Subdivision); if (checkMainSubdivisions.IsValid && checkSubordinateSubdivisions.IsValid) { var subdivision = await _database.SubdivisionsRepository.Find(x => x.Id == checkSubordinateSubdivisions.Result); var result = subdivision.Result.FirstOrDefault(); if (result != null) { result.IdSubordinate = checkMainSubdivisions.Result; await _database.SubdivisionsRepository.Update(result); return(_mapperService.Mapper.Map <ActualResult>(await _database.SaveAsync())); } return(new ActualResult(Errors.TupleDeleted)); } var listErrors = checkMainSubdivisions.ErrorsList.ToList(); listErrors.AddRange(checkSubordinateSubdivisions.ErrorsList); return(new ActualResult(listErrors)); }
public async Task <ActualResult> CreateSubordinateSubdivisionAsync(SubdivisionDTO dto) { if (!await CheckNameAsync(dto.Name) && !await CheckAbbreviationAsync(dto.Name)) { await _database.SubdivisionsRepository.Create(_mapperService.Mapper.Map <Subdivisions>(dto)); return(_mapperService.Mapper.Map <ActualResult>(await _database.SaveAsync())); } return(new ActualResult(Errors.DuplicateData)); }
public ActionResult Edit(SubdivisionDTO obj) { if (ModelState.IsValid) { subdivisionService.Add(obj); subdivisionService.Save(); return(RedirectToAction("Index")); } return(View()); }
public HttpResponseMessage Post(SubdivisionDTO address) { try { subdivisionService.Add(address); return(Request.CreateResponse(HttpStatusCode.OK, address)); } catch (Exception exc) { return(Request.CreateResponse(HttpStatusCode.BadRequest, "Не смогли получить адрес")); } }
public ActionResult Create(SubdivisionDTO subdivision, FormCollection collection) { try { // TODO: Add insert logic here unitOfWorkAddress.SubdivisionService.Add(subdivision); return(RedirectToAction("Index")); } catch { return(View()); } }
public ActionResult Edit(SubdivisionDTO subdivision, FormCollection collection) { using (unitOfWorkAddress.Transaction = new TransactionScope(TransactionScopeOption.RequiresNew)) { try { // TODO: Add update logic here unitOfWorkAddress.SubdivisionService.Update(subdivision); unitOfWorkAddress.Commit(); return(RedirectToAction("Index")); } catch { unitOfWorkAddress.Rollback(); } } return(View()); }
public async Task <ActualResult> UpdateAbbreviationSubdivisionAsync(SubdivisionDTO dto) { var check = await _hashIdUtilities.CheckDecryptWithId(dto.HashId, Enums.Services.Subdivision); if (check.IsValid) { if (!await CheckNameAsync(dto.Name)) { var subdivision = await _database.SubdivisionsRepository.Find(x => x.Id == check.Result); var result = subdivision.Result.FirstOrDefault(); if (result != null) { result.Abbreviation = dto.Abbreviation; await _database.SubdivisionsRepository.Update(result); return(_mapperService.Mapper.Map <ActualResult>(await _database.SaveAsync())); } return(new ActualResult(Errors.TupleDeleted)); } return(new ActualResult(Errors.DuplicateData)); } return(new ActualResult(check.ErrorsList)); }
static void Main(string[] args) { try { var kernel = new StandardKernel(new ServiceModule()); StreetService streetService = kernel.Get <StreetService>(); AddressService addressService = kernel.Get <AddressService>(); SubdivisionService subdivService = kernel.Get <SubdivisionService>(); Console.WriteLine("Get All"); StreetDTO s = streetService.GetAll().ToList()[0]; AddressDTO a = addressService.GetAll().ToList()[0]; SubdivisionDTO sd = subdivService.GetAll().ToList()[0]; Console.WriteLine("Works"); //Console.WriteLine($"{s.StreetId} {s.StreetName}"); //Console.WriteLine($"{a.House} {a.Latitude} {a.Longitude} {a.Serial} {a.StreetId} {a.SubdivisionId} {a.СountEntrance} {a.СountFloor}"); //Console.WriteLine($"{sd.SubdivisionId} {sd.SubdivisionName}"); Console.WriteLine(""); Console.WriteLine("Get"); Console.WriteLine("Works"); //s = streetService.Get(1); //a = addressService.Get(1); //sd = subdivService.Get(1); //Console.WriteLine($"{s.StreetId} {s.StreetName}"); //Console.WriteLine($"{a.House} {a.Latitude} {a.Longitude} {a.Serial} {a.StreetId} {a.SubdivisionId} {a.СountEntrance} {a.СountFloor}"); //Console.WriteLine($"{sd.SubdivisionId} {sd.SubdivisionName}"); Console.WriteLine(""); Console.WriteLine("Add"); Console.WriteLine("Works"); s = new StreetDTO() { StreetName = "Тестовая Улица 1" }; a = new AddressDTO() { House = "TestAddress1", Latitude = decimal.Zero, Longitude = decimal.Zero, Serial = "Test Serial1", StreetId = streetService.GetAll().Last().StreetId, SubdivisionId = subdivService.GetAll().Last().SubdivisionId, СountEntrance = 0, СountFloor = 0 }; sd = new SubdivisionDTO() { SubdivisionName = "SubDiv Test1" }; //Console.WriteLine(streetService.Add(s)); //Console.WriteLine(addressService.Add(a).House); //Console.WriteLine(a.House); //Console.Write(addressService.GetAll().Where(g => g.House == a.House).FirstOrDefault().AddressId); //Console.WriteLine(subdivService.Add(sd)); Console.WriteLine(""); Console.WriteLine("Update"); Console.WriteLine("Address update ?"); //streetService.Update(new StreetDTO() { StreetId = streetService.GetAll().Last().StreetId, StreetName = "Updated Street" }); //addressService.Update(new AddressDTO() { AddressId = addressService.GetAll().Last().AddressId, House = "Updated Address" }); //subdivService.Update(new SubdivisionDTO() { SubdivisionId = subdivService.GetAll().Last().SubdivisionId, SubdivisionName = "Updated SubDiv" }); //Console.WriteLine(streetService.GetAll().Last().StreetName); //Console.WriteLine(addressService.GetAll().Last().House); //Console.WriteLine(subdivService.GetAll().Last().SubdivisionName); Console.WriteLine(""); Console.WriteLine("Delete"); Console.WriteLine(streetService.Delete(streetService.GetAll().Last()).StreetName); Console.WriteLine(addressService.Delete(addressService.GetAll().Last()).House); Console.WriteLine(subdivService.Delete(subdivService.GetAll().Last()).SubdivisionName); Console.ReadKey(); } catch (Exception ex) { throw ex; } }
public ActionResult Edit(int id) { SubdivisionDTO model = (id == 0) ? new SubdivisionDTO() : subdivisionService.Get(id); return(View(model)); }
public ActionResult Create() { var model = new SubdivisionDTO(); return(View(model)); }