示例#1
0
        public static QuotationVm GetQuotationInfo(int quotationId, byte orderFrom)
        {
            QuotationVm quotationVm = new QuotationVm(orderFrom);

            if (quotationId == 0)
            {
                QuotationContainerVm quotContVm = new QuotationContainerVm();
                quotationVm.QuotationContainers.Add(quotContVm);
            }
            else
            {
                OperationsEntities db = new OperationsEntities();
                var quotDb            = db.Quotations.Include("QuotationContainers")
                                        .Where(x => x.QuoteId == quotationId).FirstOrDefault();

                Mapper.CreateMap <Quotation, QuotationVm>().IgnoreAllNonExisting();
                Mapper.CreateMap <QuotationContainer, QuotationContainerVm>().IgnoreAllNonExisting();
                Mapper.Map(quotDb, quotationVm);

                if (quotationVm.QuotationContainers.Count == 0)
                {
                    QuotationContainerVm quotContVm = new QuotationContainerVm();
                    quotationVm.QuotationContainers.Add(quotContVm);
                }
            }
            return(quotationVm);
        }
示例#2
0
        public ActionResult Add(int id = 0, byte orderFrom = 1)
        {
            #region Check Rights
            bool hasRights;
            if (orderFrom == 1) //Check export rights
            {
                if (id == 0)
                {
                    hasRights = AdminHelper.CheckUserAction(ScreenEnum.ExportQuotation, ActionEnum.Add);
                }
                else
                {
                    hasRights = AdminHelper.CheckUserAction(ScreenEnum.ExportQuotation, ActionEnum.Edit);
                }
            }
            else
            {
                if (id == 0)
                {
                    hasRights = AdminHelper.CheckUserAction(ScreenEnum.ImportQuotation, ActionEnum.Add);
                }
                else
                {
                    hasRights = AdminHelper.CheckUserAction(ScreenEnum.ImportQuotation, ActionEnum.Edit);
                }
            }


            if (!hasRights)
            {
                return(RedirectToAction("UnAuthorized", "Home"));
            }
            #endregion

            QuotationVm quotationsVm = QuotationHelper.GetQuotationInfo(id, orderFrom);

            ViewBag.CarrierList      = ListCommonHelper.GetCarrierList("en", 1);
            ViewBag.ShipperList      = ListCommonHelper.GetShipperList();
            ViewBag.ConsigneeList    = ListCommonHelper.GetConsigneeList();
            ViewBag.NotifierList     = ListCommonHelper.GetNotifierList(0);
            ViewBag.IncotermLib      = ListCommonHelper.GetIncotermLibList();
            ViewBag.Containers       = ListCommonHelper.GetContainerList();
            ViewData["PortList"]     = ListCommonHelper.GetPortsGrouped("en", 1);
            ViewData["CurrencyList"] = ListCommonHelper.GetCurrencyList();
            ViewBag.AgentList        = ListCommonHelper.GetAgentList();

            return(View(quotationsVm));
        }
示例#3
0
        public ActionResult AddEditQuotation(QuotationVm quotationVm)
        {
            string isSaved = QuotationHelper.AddEditQuotation(quotationVm);

            return(Json(isSaved));
        }
示例#4
0
        public static string AddEditQuotation(QuotationVm quoteVm)
        {
            string                    isSaved = "true";
            int                       quoteId = quoteVm.QuoteId;
            OperationsEntities        db      = new OperationsEntities();
            Quotation                 quotationDb;
            List <QuotationContainer> quotationContListDb;

            if (quoteId == 0)
            {
                quotationDb         = new Quotation();
                quotationContListDb = new List <QuotationContainer>();
            }
            else
            {
                quotationDb = db.Quotations.Include("QuotationContainers")
                              .Where(x => x.QuoteId == quoteId).FirstOrDefault();
                quotationContListDb = quotationDb.QuotationContainers.ToList();

                //Get quotContainers Ids sent from the screen
                List <int> containerVmIds = quoteVm.QuotationContainers.Select(x => x.ContainerTypeId.Value).ToList();
                var        containerDel   = quotationContListDb.Where(x => !containerVmIds.Contains(x.ContainerTypeId)).ToList();

                foreach (var item in containerDel)
                {
                    db.QuotationContainers.Remove(item);
                }
            }

            Mapper.CreateMap <QuotationVm, Quotation>().IgnoreAllNonExisting();
            Mapper.CreateMap <QuotationContainerVm, QuotationContainer>().IgnoreAllNonExisting();
            Mapper.Map(quoteVm, quotationDb);



            if (quoteId == 0)
            {
                if (quotationDb.OrderFrom == 1)
                {
                    quotationDb.QuoteCode = AdminHelper.GeneratePrefixCode(PrefixForEnum.QuoteExport, true);
                }
                else
                {
                    quotationDb.QuoteCode = AdminHelper.GeneratePrefixCode(PrefixForEnum.QuoteImport, true);
                }

                db.Quotations.Add(quotationDb);
            }

            try
            {
                db.SaveChanges();
            }
            catch (DbEntityValidationException e)
            {
                isSaved = "false " + e.Message;
            }
            catch (Exception e)
            {
                isSaved = "false " + e.Message;
            }

            return(isSaved);
        }