示例#1
0
        public IHttpActionResult CreateNewReclamations(NewReclamationDto newReclamationDto)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest());
            }

            var soldDevice = _unitOfWork.SoldDevices.GetSoldDevice(newReclamationDto.SoldDeviceId);

            if (soldDevice.ExpiredWarranty() == true)
            {
                return(BadRequest("Warranty for this device has expired."));
            }

            var reclamation = Mapper.Map <NewReclamationDto, Reclamation>(newReclamationDto);

            if (User.IsInRole(RoleName.AgentRoleName))
            {
                reclamation.Agent = _unitOfWork.Employees.GetAgent(reclamation.AgentId);
                reclamation.Create();
            }

            _unitOfWork.Reclamations.Add(reclamation);
            _unitOfWork.Complete();

            newReclamationDto.Id = reclamation.Id;
            return(Ok());
        }
示例#2
0
        public void UpdateReclamation(int id, NewReclamationDto reclamationDbo)
        {
            if (!ModelState.IsValid)
            {
                throw new HttpResponseException(HttpStatusCode.BadRequest);
            }

            var reclamationInDb = _unitOfWork.Reclamations.GetReclamation(id);

            if (reclamationInDb == null)
            {
                throw new HttpResponseException(HttpStatusCode.NotFound);
            }

            Mapper.Map(reclamationDbo, reclamationInDb);

            _unitOfWork.Complete();
        }