private void validate(StorageDTO storage) { if (string.IsNullOrEmpty(storage.Name)) { throw new ArgumentException("Name повинне містити значення!"); } }
public async Task <IActionResult> Create(StorageDTO StorageDTO) { var Storage = _mapper.Map <StorageDTO, Storage>(StorageDTO); await _unitOfWork.Storage.Add(Storage); return(CreatedAtAction(nameof(GetBy), new { id = Storage.StorageId }, Storage)); }
public async Task <IHttpActionResult> GetById(int id) { StorageDTO Storage = await StorageService.GetAll().Where(x => x.Id == id && !x.Deleted).ProjectTo <StorageDTO>().FirstOrDefaultAsync(); if (Storage == null) { return(NotFound()); } return(Ok(Storage)); }
public async Task <IHttpActionResult> Update([FromBody] StorageDTO StorageDto) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var entity = await StorageService.FindOneAsync(StorageDto.Id); entity = StorageDto.ToEntity(entity); entity.LastUserId = User.Identity.GetUserId(); entity.LastTime = DateTime.Now; await StorageService.UpdateAsync(entity); return(Ok(entity.ToModel())); }
public void SetData(StorageDTO storage) { //validation if (storage == null) { throw new ValidationException("DTO null", ""); } if (storage.Values == null) { throw new ValidationException("DTO values null", ""); } db.Write(storage.Values.ToArray()); }
public IEnumerable <int> Sort(SortDTO dto) { StorageDTO data = db.GetData(); if (data != null && data.Values != null && data.Values.Count > 0) { this.IsAscending = dto.IsAscending; var sortedData = StupidSort(data.Values); return(sortedData.Take(dto.Length)); } else { throw new ValidationException("no data to sort", ""); } }
public void SetDataDTOValuesNull() { //Arrange var mock = new Mock <IRepository>(); mock.Setup(repo => repo.GetValues()).Returns(GetFakeValues()); DataService ds = new DataService(mock.Object); //Act StorageDTO storage = new StorageDTO(); //Assert var exception = Assert.Throws <ValidationException>(() => ds.SetData(storage)); Assert.Equal("DTO values null", exception.Message); }
public IEnumerable <int> Sort(SortDTO dto) { StorageDTO data = db.GetData(); if (data != null && data.Values != null && data.Values.Count > 0) { this.isAscending = dto.IsAscending; List <int> arr = data.Values; int count = arr.Count; Quick_Sort(ref arr, 0, arr.Count - 1, ref count); return(arr.Take(dto.Length)); } else { throw new ValidationException("no data to sort", ""); } }
public void GetStorage(int cruiseId) { var storages = Module.IvStorageGetAll(cruiseId); var list = new List <StorageDTO>(); foreach (IvStorage r in storages) { var dto = new StorageDTO(); dto.Id = r.Id; dto.Name = r.Name; dto.NameTree = r.NameTree; if (r.Parent != null) { dto.ParentId = r.Parent.Id; } list.Add(dto); } HttpContext.Current.Response.ContentType = "application/json"; HttpContext.Current.Response.Charset = "utf-8"; HttpContext.Current.Response.Write(JsonConvert.SerializeObject(list)); }
public void AddStreet(StorageDTO storage) { var user = SecurityContext.GetUser(); var userType = user.GetType(); if (userType != typeof(ProductManager) && userType != typeof(StorageManager)) { throw new MethodAccessException(); } if (storage == null) { throw new ArgumentNullException(nameof(storage)); } validate(storage); var mapper = new MapperConfiguration(cfg => cfg.CreateMap <StorageDTO, Storage>()).CreateMapper(); var storageEntity = mapper.Map <StorageDTO, Storage>(storage); _database.Storages.Create(storageEntity); }
public JsonResult Post([FromBody] int[] values) { try { if (values != null) { var storageDto = new StorageDTO { Values = values.ToList() }; service.SetData(storageDto); return(Json(storageDto)); } else { return(Json("empty sequence")); } } catch (ValidationException ex) { return(Json(ex.Message)); } }
public async Task <IHttpActionResult> Create([FromBody] StorageDTO StorageDto) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var entity = StorageDto.ToEntity(); var roleId = MBHelper.GetUserRoleId(User); if (roleId == (int)RoleType.Member) { entity.StorageType = (int)StorageType.Member; } else { entity.StorageType = (int)StorageType.System; } entity.CreateUserId = User.Identity.GetUserId(); entity.CreateTime = DateTime.Now; await StorageService.InsertAsync(entity); return(Ok(entity.ToModel())); }
public async Task <IActionResult> Update(int id, StorageDTO StorageDTO) { if (StorageDTO.StorageId != id) { return(BadRequest()); } try { var Storage = _mapper.Map <StorageDTO, Storage>(StorageDTO); await _unitOfWork.Storage.Update(id, Storage); } catch (DbUpdateConcurrencyException) { if (!await StorageExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public IEnumerable <int> Sort(SortDTO dto) { StorageDTO data = db.GetData(); if (data != null && data.Values != null && data.Values.Count > 0) { List <int> sortedData; if (dto.IsAscending) { sortedData = SelectionASC(data.Values); } else { sortedData = SelectionDSC(data.Values); } return(sortedData.Take(dto.Length)); } else { throw new ValidationException("no data to sort", ""); } }
public StorageDTO Add(StorageDTO storage) { T_Storage FruitResult = _dal.Insert <T_Storage>(Mapper.Map <T_Storage>(storage)); return(Mapper.Map <StorageDTO>(FruitResult)); }
public StorageE StorageDTO2StorageE(StorageDTO Storage) { return(new StorageE { ID = Storage.ID, Name = Storage.Name, Distance = Storage.Distance }); }
public async Task Create(StorageDTO storage) { await storageRepository.Create(storage); }
public void Renew(StorageDTO storage) { _dal.Update <T_Storage>(Mapper.Map <T_Storage>(storage), true); }
public static Storage ToEntity(this StorageDTO dto, Storage entity) { return(Mapper.Map(dto, entity)); }
public static Storage ToEntity(this StorageDTO dto) { return(Mapper.Map <StorageDTO, Storage>(dto)); }