protected override void InitializeMockData()
        {
            firstProduct = new Product {
                Id = 1, Name = "Blade", Description = "x35 Blade F12"
            };
            secondProduct = new Product {
                Id = 2, Name = "Blade F1", Description = "x35 Blade F10"
            };
            firstDefect = new Defect {
                Id = 1, Name = "DI321", Description = "x35 Blade F12", Product = firstProduct
            };
            secondDefect = new Defect {
                Id = 2, Name = "CO410", Description = "x35 Blade F10", Product = firstProduct
            };
            products = new List <Product>()
            {
                firstProduct, secondProduct
            };
            defects = new List <Defect>()
            {
                firstDefect, secondDefect
            };
            defectUpdated = new Defect {
                Id = 2, Name = "CO410", Description = "x35 Blade F10", Product = firstProduct
            };

            dto = new DefectDto {
                Id = 1, Name = "DI230", Description = "x35 Blade F12", ProductId = firstProduct.Id
            };
        }
Beispiel #2
0
        public async Task UpdateDefect(DefectDto defect)
        {
            var tempDefect = await _defectRepository.GetByIdAsync(defect.Id);

            tempDefect.Type = defect.Type;
            _defectRepository.Update(tempDefect);
            await _defectRepository.SaveAsync();
        }
Beispiel #3
0
 public Defect Create(DefectDto dto, User user)
 {
     return(new Defect(user)
     {
         Name = dto.Name,
         Description = dto.Description,
         ProductId = dto.ProductId
     });
 }
Beispiel #4
0
        public async Task <ActionResult> PutDefect(long id, [FromBody] DefectDto defect)
        {
            if (id != defect.Id)
            {
                return(BadRequest());
            }

            await _defectService.UpdateDefect(defect);

            return(Ok());
        }
Beispiel #5
0
        public async Task <IHttpActionResult> Add([FromBody] DefectDto dto)
        {
            try
            {
                var user = await GetUserAsync();

                var defect = _factory.Create(dto, user);
                _unitOfWork.DefectRepository.Add(defect);
                await _unitOfWork.SaveChangesAsync();
            }
            catch (Exception ex)
            {
                await LogExceptionAsync(ex);

                return(BadRequest(ex.Message));
            }
            return(Ok());
        }
Beispiel #6
0
        public async Task <IHttpActionResult> Update([FromBody] DefectDto dto)
        {
            var defect = await _unitOfWork.DefectRepository.FindByIdAsync(dto.Id);

            if (defect == null)
            {
                return(NotFound());
            }
            try
            {
                var user = await GetUserAsync();

                defect.Update(user, dto.Name, dto.Description);
                _unitOfWork.DefectRepository.Update(defect);
                await _unitOfWork.SaveChangesAsync();
            }
            catch (Exception ex)
            {
                await LogExceptionAsync(ex);

                return(BadRequest(ex.Message));
            }
            return(Ok());
        }