Example #1
0
        public HttpResponseMessage CreateDetail(HttpRequestMessage request, string importDetailViewModels)
        {
            return(CreateHttpResponse(request, () =>
            {
                HttpResponseMessage response = null;
                if (!ModelState.IsValid)
                {
                    response = request.CreateResponse(HttpStatusCode.BadRequest, ModelState);
                }
                else
                {
                    if (importDetailViewModels != null)
                    {
                        var newImportDetail = new ImportDetail();
                        var listImportDetailViewModels = new JavaScriptSerializer().Deserialize <List <ImportDetailViewModel> >(importDetailViewModels);
                        foreach (var importDetailViewModel in listImportDetailViewModels)
                        {
                            newImportDetail.UpdateImportDetail(importDetailViewModel);

                            _importDetailService.Add(newImportDetail);
                            _importDetailService.Save();
                        }
                    }

                    //var responseData = Mapper.Map<Import, ImportViewModel>(newImport);
                    response = request.CreateResponse(HttpStatusCode.Created);
                }

                return response;
            }));
        }
Example #2
0
 public HttpResponseMessage Create(HttpRequestMessage request, ImportViewModel importViewModel)
 {
     return(CreateHttpResponse(request, () =>
     {
         HttpResponseMessage response = null;
         if (!ModelState.IsValid)
         {
             response = request.CreateResponse(HttpStatusCode.BadRequest, ModelState);
         }
         else
         {
             var newImportModel = new Import();
             var newImportDetailModel = new ImportDetail();
             var identity = (ClaimsIdentity)User.Identity;
             IEnumerable <Claim> claims = identity.Claims;
             newImportModel.UpdateImport(importViewModel);
             _importService.Add(newImportModel);
             _importService.Save();
             foreach (var item in importViewModel.ImportDetails)
             {
                 newImportDetailModel.UpdateImportDetail(item);
                 _importDetailService.Add(newImportDetailModel);
                 _importDetailService.Save();
             }
             Log log = new Log()
             {
                 AppUserId = claims.FirstOrDefault().Value,
                 Content = Notification.CREATE_IMPORT,
                 Created = DateTime.Now
             };
             _logService.Create(log);
             _logService.Save();
             var responseData = Mapper.Map <Import, ImportViewModel>(newImportModel);
             response = request.CreateResponse(HttpStatusCode.OK, responseData);
         }
         return response;
     }));
 }