Beispiel #1
0
 public ActionResult AddOrEdit(_Distributor distributor)
 {
     if (distributor.DistributorId == 0)
     {
         if (distributorService.Add(distributor))
         {
             return(Json(new { success = true, message = "Add successfully" }, JsonRequestBehavior.AllowGet));
         }
         else
         {
             return(Json(new { success = false, message = "Failed to add" }, JsonRequestBehavior.AllowGet));
         }
     }
     else
     {
         if (distributorService.Edit(distributor))
         {
             return(Json(new { success = true, message = "Edit successfully" }, JsonRequestBehavior.AllowGet));
         }
         else
         {
             return(Json(new { success = false, message = "Failed to edit" }, JsonRequestBehavior.AllowGet));
         }
     }
 }
Beispiel #2
0
        public ActionResult Remove(int id)
        {
            _Distributor distributor = distributorService.GetOne(id);

            distributorService.Delete(distributor);
            return(Json(new { success = true, message = "Removal success!" }, JsonRequestBehavior.AllowGet));
        }
Beispiel #3
0
        public ActionResult DeleteConfirmed(int id)
        {
            _Distributor distributor = distributorService.GetOne(id);

            distributorService.Delete(distributor);
            return(RedirectToAction("Index"));
        }
Beispiel #4
0
        public ActionResult Details(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            Order order = orderService.FindById(Convert.ToInt32(id));

            if (order == null)
            {
                return(HttpNotFound());
                //throw new HttpException(404, "Some description");
            }
            else
            {
                _Distributor distributor = distributorService.GetOne(order.DistributorId);
                Employee     employee    = employeeService.GetOne(order.EmployeeId);
                ViewBag.EmpInfoName = employee.EmpName;
                ViewBag.EmpInfoId   = employee.EmployeeId;
                List <OrderDetail> detail  = detailService.FindByOrderId(order.OrderId);
                Invoice            invoice = invoiceService.FindByOrderId(order.OrderId);

                return(View(Tuple.Create(distributor, order, detail)));
            }
        }
Beispiel #5
0
 public ActionResult Edit([Bind(Include = "DistributorId,CategoryName,Description")] _Distributor distributor)
 {
     if (ModelState.IsValid)
     {
         distributorService.Edit(distributor);
         return(RedirectToAction("Index"));
     }
     return(View(distributor));
 }
Beispiel #6
0
        // GET: Categories/Details/5
        public ActionResult Details(int id)
        {
            if (id == 0)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            _Distributor distributor = distributorService.GetOne(id);

            if (distributor == null)
            {
                return(HttpNotFound());
            }
            return(View(distributor));
        }
Beispiel #7
0
        public ActionResult AddOrEdit(int id = 0)
        {
            List <Region> regions = regionService.GetAll();

            ViewBag.RegionId = new SelectList(regions, "RegionId", "RegionName");

            if (id == 0)
            {
                return(View(new _Distributor()));
            }
            else
            {
                _Distributor distributor = distributorService.GetOne(id);
                return(View(distributor));
            }
        }
        public _Distributor GetOne(int id)
        {
            _logger.Info("Start fetch single _Distributor");
            _Distributor _Distributor = null;

            _Distributor = repoDistributor.GetById(id);
            if (_Distributor == null)
            {
                _logger.Info("this _Distributor not existed");
            }
            else
            {
                _logger.Info("Got this _Distributor");
            }
            _logger.Info("End fetch single _Distributor");
            return(_Distributor);
        }
        public bool Edit(_Distributor _Distributor)
        {
            bool success;

            _logger.Info("Start Editing");
            repoDistributor.Attach(_Distributor);
            success = (_uow.SaveChange() > 0);
            if (success == true)
            {
                _logger.Info("successfull Edited _Distributor");
            }
            else
            {
                _logger.Info("failed to Edit");
            }
            _logger.Info("End Edit a _Distributor");
            return(success);
        }
        public bool Delete(_Distributor _Distributor)
        {
            bool success;

            _logger.Info("Start deleting");
            repoDistributor.Delete(_Distributor);
            success = _uow.SaveChange() > 0;
            if (success == true)
            {
                _logger.Info("successfull deteled _Distributor");
            }
            else
            {
                _logger.Info("failed to delete");
            }
            _logger.Info("End delete a _Distributor");
            return(success);
        }
        //    public _Distributor FindById(int Id)
        //    {
        //        return repoDistributor.GetById(Id);
        //    }
        //    public bool AddRange(List<_Distributor> distributors)
        //    {

        //        bool success=false;
        //        _logger.Info("Start add a list Region");
        //        try
        //        {
        //            repoDistributor.AddRange(distributors);
        //            _uow.SaveChange();
        //            success = true;

        //        }
        //        catch(DbEntityValidationException e)
        //        {
        //            foreach(var eve in e.EntityValidationErrors)
        //            {
        //                Console.WriteLine("Entity of type \"{0}\" in state \"{1}\" has the following validation errors:",
        //                 eve.Entry.Entity.GetType().Name, eve.Entry.State);
        //                foreach (var ve in eve.ValidationErrors)
        //                {
        //                    Console.WriteLine("- Property: \"{0}\", Error: \"{1}\"",
        //                        ve.PropertyName, ve.ErrorMessage);
        //                }
        //            }
        //            throw;
        //        }

        //        //success = (_uow.SaveChange() == distributors.Count()) ? true : false;
        //        if (success == true)
        //            _logger.Info("successfull added list Region");
        //        else
        //            _logger.Info("failed to add");
        //        _logger.Info("End add a list _Distributor list Region");
        //        return success;
        //    }

        //    #endregion
        //

        public bool Add(_Distributor _Distributor)
        {
            bool success;

            _logger.Info("Start add new _Distributor");
            repoDistributor.Add(_Distributor);
            _logger.Info("End add new _Distributor");
            success = (_uow.SaveChange() > 0) ? true : false;
            if (success == true)
            {
                _logger.Info("successfull added _Distributor");
            }
            else
            {
                _logger.Info("failed to add");
            }
            _logger.Info("End add a list _Distributor _Distributor");
            return(success);
        }
        public ActionResult PrintInvoice(int?orderId)
        {
            if (orderId == null)
            {
                return(null);
            }
            int   _orderId = Convert.ToInt32(orderId);
            Order order    = orderService.FindById(_orderId);

            if (order == null)
            {
                return(null);
            }

            // get distributor info
            _Distributor distributor = distributorService.GetOne(order.DistributorId);

            // get cashier info
            Employee employee = employeeService.FindById(order.EmployeeId);

            // get order detail info
            //List<OrderDetail> detail = detailService.FindByOrderId(order.OrderId);


            ReportDocument rd = new ReportDocument();

            rd.Load(Path.Combine(Server.MapPath("~/Reports/InvoiceCrystal.rpt")));


            //CrystalReportViewer crysReportViewer = new CrystalReportViewer();

            //InvoiceCrystal report = new InvoiceCrystal();

            // set list order detail  info


            using (ManagementDistributorDbContext dbContext = new ManagementDistributorDbContext())
            {
                rd.SetDataSource(dbContext.OrderDetails.Select(od => new
                {
                    od.OrderId,
                    od.OrderDetailId,
                    od.ActualQuantity,
                    od.Price,
                    od.ProductId,
                    od.Product.ProductName,
                }
                                                               ).ToList());
            }
            //rd.SetDataSource(detail);

            // set order generic info
            //rd.SetParameterValue("OrderDate", order.OrderDate);
            rd.SetParameterValue("OrderId", order.OrderId);

            rd.SetParameterValue("OrderToTalAmount", order.ToTalAmount);

            rd.SetParameterValue("InvoiceDate", DateTime.Now);
            rd.SetParameterValue("InvoiceId", 1);
            //rd.SetParameterValue("DueDate", DateTime.Now); //

            // Set Distributor Info
            rd.SetParameterValue("DistributorName", distributor.DistributorName);
            rd.SetParameterValue("DistributorAddress", distributor.DistributorAddress);

            // set Cashier info
            rd.SetParameterValue("EmployeeName", employee.EmpName);


            //crysReportViewer.ReporSource = report;

            Response.Buffer = false;
            Response.ClearContent();
            Response.ClearHeaders();

            try
            {
                Stream stream = rd.ExportToStream(CrystalDecisions.Shared.ExportFormatType.PortableDocFormat);
                stream.Seek(0, SeekOrigin.Begin);


                return(File(stream, "application/pdf", "Invoice.pdf"));
            }
            catch (Exception ex)
            {
                string path = @"C:/PrintInvoice.Exception.txt";
                ExceptionProofer.LogToFile(path, ex);
                return(null);
            }
        }