Exemplo n.º 1
0
        public ActionResult Edit(string Pattern, int id)
        {
            ICompanyService        comSrv     = IoC.Resolve <ICompanyService>();
            Company                currentCom = comSrv.Getbykey(((EInvoiceContext)FXContext.Current).CurrentCompany.id);
            IPublishInvoiceService _PubIn     = IoC.Resolve <IPublishInvoiceService>();
            IRegisterTempService   _ReTemSvc  = IoC.Resolve <IRegisterTempService>();
            string ViewName = InvServiceFactory.GetView(Pattern, currentCom.id) + "Edit";
            //khoi tao service
            IInvoiceService IInvSrv = InvServiceFactory.GetService(Pattern, currentCom.id);
            //lay ve mot ban ghi hoa don
            IInvoice model = IInvSrv.Getbykey <IInvoice>(id);

            if (model.Status != InvoiceStatus.NewInv)
            {
                Messages.AddErrorFlashMessage("Không thể sửa hóa đơn này.");
                return(RedirectToAction("Index", new { Pattern = Pattern, Serial = model.Serial }));
            }
            //lay va doi danh sach cac san pham thanh doi tuong json
            //nếu Unit=null thì mặc định hiển thị ""
            foreach (var item in model.Products)
            {
                if (item.Unit == null)
                {
                    item.Unit = "";
                }
            }
            //lay ra danh sach cac serial
            List <string> ser = _PubIn.GetSerialByPatter(model.Pattern, currentCom.id);

            ViewData["ser"] = ser;
            //lay thong tin ve don vi ban hang
            ViewData["company"] = currentCom;
            model.Note          = "";
            return(View(ViewName, model));
        }
Exemplo n.º 2
0
        public ActionResult UpdateCoupon(string Pattern, int id)
        {
            if (id <= 0)
            {
                throw new HttpRequestValidationException();
            }
            ICompanyService        comSrv     = IoC.Resolve <ICompanyService>();
            Company                currentCom = comSrv.Getbykey(((EInvoiceContext)FXContext.Current).CurrentCompany.id);
            IPublishInvoiceService _PubIn     = IoC.Resolve <IPublishInvoiceService>();
            IRegisterTempService   _ReTemSvc  = IoC.Resolve <IRegisterTempService>();
            IInvoiceService        IInvSrv    = InvServiceFactory.GetService(Pattern, currentCom.id);
            IInvoice               model      = IInvSrv.Getbykey <IInvoice>(id);
            string NoteOrder = model.Note;

            try
            {
                TryUpdateModelFromType(model.GetType(), model);
                model.Note = NoteOrder + " || " + model.Note;
                IInvSrv.Update(model);
                IInvSrv.CommitChanges();
                log.Info("Edit EInvoice by: " + HttpContext.User.Identity.Name + " Info-- TenKhachHang: " + model.CusName + " MaKhachHang: " + model.CusCode + " SoTien: " + model.Amount);
                Messages.AddFlashMessage("Sửa phiếu thu thành công.");
                return(RedirectToAction("Index", new { Pattern = Pattern, Serial = model.Serial }));
            }
            catch (HttpRequestValidationException ex)
            {
                log.Error("ArgumentException: " + ex);
                Messages.AddErrorMessage("Dữ liệu không hợp lệ hoặc có chứa mã gây nguy hiểm tiềm tàng cho hệ thống!");
                model = IInvSrv.Getbykey <IInvoice>(id);
                List <string> ser = _PubIn.GetSerialByPatter(Pattern, currentCom.id);
                ViewData["ser"]     = ser;
                ViewData["company"] = currentCom;
                string ViewName = InvServiceFactory.GetView(Pattern, currentCom.id) + "Edit";
                return(View(ViewName, model));
            }
            catch (Exception ex)
            {
                log.Error("Edit -", ex);
                model.Name = _ReTemSvc.SeachNameInv(Pattern, currentCom.id);
                List <string> ser = _PubIn.GetSerialByPatter(model.Pattern, currentCom.id);
                ViewData["ser"]     = ser;
                ViewData["company"] = currentCom;
                Messages.AddErrorMessage("Có lỗi xảy ra, vui lòng thực hiện lại.");
                string ViewName = InvServiceFactory.GetView(Pattern, currentCom.id) + "Edit";
                return(View(ViewName, model));
            }
        }
Exemplo n.º 3
0
        public ActionResult Create(string Pattern)
        {
            ICompanyService        comSrv     = IoC.Resolve <ICompanyService>();
            Company                currentCom = comSrv.Getbykey(((EInvoiceContext)FXContext.Current).CurrentCompany.id);
            IPublishInvoiceService _PubIn     = IoC.Resolve <IPublishInvoiceService>();
            IRegisterTempService   _ReTemSvc  = IoC.Resolve <IRegisterTempService>();
            string   ViewName = InvServiceFactory.GetView(Pattern, currentCom.id) + "Create";
            IInvoice model    = InvServiceFactory.NewInstance(Pattern, currentCom.id);

            model.Pattern = Pattern;
            model.ComID   = currentCom.id;
            model.Name    = _ReTemSvc.SeachNameInv(Pattern, currentCom.id);
            List <string> ser = _PubIn.GetSerialByPatter(Pattern, currentCom.id);

            if (ser.Count == 0)
            {
                Messages.AddErrorFlashMessage("Dải số đã hết hoặc đã bị hủy.");
                return(RedirectToAction("Index", new { Pattern = Pattern }));
            }
            ViewData["ser"]     = ser;
            ViewData["company"] = currentCom;
            return(View(ViewName, model));
        }
Exemplo n.º 4
0
        public ActionResult Edit(string Pattern, int id, string PubDatasource)
        {
            if (id <= 0)
            {
                throw new HttpRequestValidationException();
            }
            ICompanyService        comSrv     = IoC.Resolve <ICompanyService>();
            Company                currentCom = comSrv.Getbykey(((EInvoiceContext)FXContext.Current).CurrentCompany.id);
            IPublishInvoiceService _PubIn     = IoC.Resolve <IPublishInvoiceService>();
            IRegisterTempService   _ReTemSvc  = IoC.Resolve <IRegisterTempService>();
            IInvoiceService        IInvSrv    = InvServiceFactory.GetService(Pattern, currentCom.id);
            IInvoice               model      = IInvSrv.Getbykey <IInvoice>(id);
            string NoteOrder = model.Note;

            try
            {
                string ErrorMessage = "";
                TryUpdateModelFromType(model.GetType(), model);
                model.CusCode = !string.IsNullOrWhiteSpace(model.CusCode) ? model.CusCode : model.CusTaxCode;
                model.Note    = NoteOrder + " || " + model.Note;
                if (!String.IsNullOrEmpty(PubDatasource) && PubDatasource != "[]")
                {
                    ICustomerService _CusSvc = FX.Core.IoC.Resolve <ICustomerService>();
                    var Typecus = (from c in _CusSvc.Query where c.Code == model.CusCode && c.CusType == 1 select c.CusType).FirstOrDefault();
                    if (Typecus == 0)
                    {
                        model.CusSignStatus = cusSignStatus.NocusSignStatus;
                    }
                    else
                    {
                        model.CusSignStatus = cusSignStatus.NoSignStatus;
                    }
                    IList <ProductInv> lstproduct = (IList <ProductInv>)PubDatasource.DeserializeJSON <ProductInv>(typeof(IList <ProductInv>));

                    if (IInvSrv.UpdateInvoice(lstproduct, model, out ErrorMessage) == true)
                    {
                        log.Info("Edit EInvoice by: " + HttpContext.User.Identity.Name + " Info-- TenKhachHang: " + model.CusName + " MaKhachHang: " + model.CusCode + " SoTien: " + model.Amount);
                        Messages.AddFlashMessage("Cập nhật hóa đơn thành công.");
                        return(RedirectToAction("Index", new { Pattern = Pattern, Serial = model.Serial }));
                    }
                    else
                    {
                        Messages.AddErrorMessage(ErrorMessage);
                    }
                    model.Products = (from pr in lstproduct select pr as IProductInv).ToList();
                }
                else
                {
                    Messages.AddErrorMessage("Chưa nhập thông tin sản phẩm");
                }
                model.Name = _ReTemSvc.SeachNameInv(Pattern, currentCom.id);
                List <string> ser = _PubIn.GetSerialByPatter(model.Pattern, currentCom.id);
                ViewData["ser"]     = ser;
                ViewData["company"] = currentCom;
                string ViewName = InvServiceFactory.GetView(Pattern, currentCom.id) + "Edit";
                return(View(ViewName, model));
            }
            catch (HttpRequestValidationException ex)
            {
                log.Error("ArgumentException: " + ex);
                Messages.AddErrorMessage("Dữ liệu không hợp lệ hoặc có chứa mã gây nguy hiểm tiềm tàng cho hệ thống!");
                model = IInvSrv.Getbykey <IInvoice>(id);
                List <string> ser = _PubIn.GetSerialByPatter(Pattern, currentCom.id);
                ViewData["ser"]     = ser;
                ViewData["company"] = currentCom;
                string ViewName = InvServiceFactory.GetView(Pattern, currentCom.id) + "Edit";
                return(View(ViewName, model));
            }
            catch (Exception ex)
            {
                log.Error("Edit -", ex);
                model.Name = _ReTemSvc.SeachNameInv(Pattern, currentCom.id);
                List <string> ser = _PubIn.GetSerialByPatter(model.Pattern, currentCom.id);
                ViewData["ser"]     = ser;
                ViewData["company"] = currentCom;
                Messages.AddErrorMessage("Có lỗi xảy ra, vui lòng thực hiện lại");
                if (!String.IsNullOrEmpty(PubDatasource))
                {
                    IList <ProductInv> lstproduct = (IList <ProductInv>)PubDatasource.DeserializeJSON <ProductInv>(typeof(IList <ProductInv>));
                    model.Products = (from pr in lstproduct select pr as IProductInv).ToList();
                }
                string ViewName = InvServiceFactory.GetView(Pattern, currentCom.id) + "Edit";
                return(View(ViewName, model));
            }
        }