Exemple #1
0
 private void validate(StorageDTO storage)
 {
     if (string.IsNullOrEmpty(storage.Name))
     {
         throw new ArgumentException("Name повинне містити значення!");
     }
 }
Exemple #2
0
        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));
        }
Exemple #3
0
        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));
        }
Exemple #4
0
        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()));
        }
Exemple #5
0
        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());
        }
Exemple #6
0
        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", "");
            }
        }
Exemple #7
0
        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);
        }
Exemple #8
0
        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", "");
            }
        }
Exemple #9
0
        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));
        }
Exemple #10
0
        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);
        }
Exemple #11
0
 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));
     }
 }
Exemple #12
0
        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()));
        }
Exemple #13
0
 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());
 }
Exemple #14
0
        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));
        }
Exemple #16
0
 public StorageE StorageDTO2StorageE(StorageDTO Storage)
 {
     return(new StorageE {
         ID = Storage.ID, Name = Storage.Name, Distance = Storage.Distance
     });
 }
Exemple #17
0
 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);
 }
Exemple #19
0
 public static Storage ToEntity(this StorageDTO dto, Storage entity)
 {
     return(Mapper.Map(dto, entity));
 }
Exemple #20
0
 public static Storage ToEntity(this StorageDTO dto)
 {
     return(Mapper.Map <StorageDTO, Storage>(dto));
 }