예제 #1
0
        public ActionResult Save(ZOOATViewModel model)
        {
            ViewBag.AgreementMethod = new SelectList(itemService.GetItemByCode(Category.AGREEMENT_METHOD), "Code", "Name", model.Method);
            ViewBag.Status          = new SelectList(itemService.GetItemByCode(Category.AGREEMENT_STATUS), "Code", "Name", model.Status);
            ViewBag.DocumentTypes   = new SelectList(itemService.GetItemByCode(Category.DOCUMENT_TYPE), "Code", "Name", model.Type);
            ViewBag.PaymentTerms    = new SelectList(itemService.GetItemByCode(Category.PAYMENT_TERM), "Code", "Name");
            ViewBag.AgreementTypes  = new SelectList(itemService.GetItemByCode(Category.AGREEMENT_TYPE), "Code", "Name");
            ViewBag.Origins         = detailService.GetOriginalList();
            ViewBag.UoMs            = detailService.GetMeasureList();

            ViewBag.LineStatus  = itemService.GetItemByCode("LINE_STATUS");
            ViewBag.NotifyQty   = itemService.GetItemByCode("NOTIFY_QTY");
            ViewBag.TenderTypes = itemService.GetItemByCode("TENDER_TYPE");

            var ownerList = service.GetOwnerList();

            ViewBag.Owners = new SelectList(ownerList, "Code", "Name");

            if (model.Details == null)
            {
                model.Details = new List <ZOAT1TMPViewModel>();
            }

            if (ModelState.IsValid)
            {
                try
                {
                    ZOOAT m = new ZOOAT();
                    AutoMapper.Mapper.Map(model, m, typeof(ZOOATViewModel), typeof(ZOOAT));
                    if (service.Save(m))
                    {
                        //save details
                        int res = 0;
                        foreach (var item in model.Details)
                        {
                            var detail = new ZOAT1TMP();
                            AutoMapper.Mapper.Map(item, detail, typeof(ZOAT1TMPViewModel), typeof(ZOAT1TMP));
                            detailService.Save(detail);
                            res = res + detail.Err;
                        }
                        if (res == 0)
                        {
                            return(RedirectToAction("Index"));
                        }
                    }
                }
                catch (Exception ex)
                {
                    ModelState.AddModelError("Service", ex.Message);
                    return(View("Create", model));
                }
            }
            return(View("Create", model));
        }
예제 #2
0
 public int Save(ZOAT1TMP detail)
 {
     SqlHelper.ExecuteSP("usp_MD_SaveBlanketAgreementDetails", detail);
     return(detail.Err);
 }