public HandleState AddOrUpdateManifest(CsManifestEditModel model)
        {
            try
            {
                var manifest = mapper.Map <CsManifest>(model);
                manifest.CreatedDate = DateTime.Now;
                var hs = new HandleState();
                manifest.RefNo = GetManifestNo(model.JobId);
                if (DataContext.Any(x => x.JobId == model.JobId))
                {
                    hs = DataContext.Update(manifest, x => x.JobId == model.JobId);
                }
                else
                {
                    hs = DataContext.Add(manifest);
                }
                if (hs.Success)
                {
                    foreach (var item in model.CsTransactionDetails)
                    {
                        if (item.IsRemoved)
                        {
                            item.ManifestRefNo = null;
                        }
                        else
                        {
                            item.ManifestRefNo = manifest.RefNo;
                        }
                        item.DatetimeModified = DateTime.Now;
                        item.UserModified     = manifest.UserCreated;
                        var tranDetail = mapper.Map <CsTransactionDetail>(item);
                        var s          = transactionDetailRepository.Update(tranDetail, x => x.Id == tranDetail.Id);
                    }
                    transactionDetailRepository.SubmitChanges();
                    DataContext.SubmitChanges();
                }

                return(hs);
            }
            catch (Exception ex)
            {
                var hs = new HandleState(ex.Message);
                return(hs);
            }
        }
Ejemplo n.º 2
0
        public IActionResult AddOrUpdateManifest(CsManifestEditModel model)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest());
            }
            model.UserCreated = model.UserModified = currentUser.UserID;
            model.CreatedDate = model.ModifiedDate = DateTime.Now;
            var          hs      = manifestService.AddOrUpdateManifest(model);
            var          message = HandleError.GetMessage(hs, Crud.Insert);
            ResultHandle result  = new ResultHandle {
                Status = hs.Success, Message = stringLocalizer[message].Value
            };

            if (!hs.Success)
            {
                return(BadRequest(result));
            }
            return(Ok(result));
        }