Ejemplo n.º 1
0
        public ResultInfo UpdateTakeMailer(string user, UpdateTakeMailerReceive info)
        {
            var result = new ResultInfo()
            {
                error = 0,
                msg   = "success"
            };
            var checkUser = db.BS_Employees.Where(p => p.UserLogin == user).FirstOrDefault();

            if (checkUser == null)
            {
                return(new ResultInfo()
                {
                    error = 1,
                    msg = "Sai thông tin"
                });
            }
            try
            {
                var checkDocument = db.MM_TakeMailers.Find(info.documentId);

                if (checkDocument == null)
                {
                    throw new Exception("Sai thông tin");
                }

                var checkMailer = db.MM_Mailers.Find(info.mailers);

                var findDetail = db.MM_TakeDetails.Where(p => p.DocumentID == checkDocument.DocumentID && p.MailerID == info.mailers).FirstOrDefault();

                if (findDetail == null || checkMailer == null)
                {
                    throw new Exception("Sai thông tin");
                }

                findDetail.StatusID        = 8;
                findDetail.TimeTake        = DateTime.Now;
                db.Entry(findDetail).State = System.Data.Entity.EntityState.Modified;
                db.SaveChanges();

                checkMailer.CurrentStatusID = 8;
                checkMailer.LastUpdateDate  = DateTime.Now;
                checkMailer.Weight          = info.weight;


                var price = db.CalPrice(checkMailer.Weight, checkMailer.SenderID, checkMailer.RecieverProvinceID, checkMailer.MailerTypeID, checkMailer.PostOfficeAcceptID, DateTime.Now.ToString("yyyy-MM-dd")).FirstOrDefault();


                checkMailer.Price        = price;
                checkMailer.PriceDefault = price;
                checkMailer.Amount       = price + checkMailer.PriceCoD + checkMailer.PriceService;

                db.Entry(checkMailer).State = System.Data.Entity.EntityState.Modified;
                db.SaveChanges();

                HandleHistory.AddTracking(8, info.mailers, checkMailer.CurrentPostOfficeID, "Đã lấy hàng, đang giao về kho. Cập nhật trọng lượng: " + info.weight + " Gram");

                var checkCount = db.TAKEMAILER_GETDETAILs(checkDocument.DocumentID).Where(p => p.CurrentStatusID == 7).ToList();

                if (checkCount.Count() == 0)
                {
                    checkDocument.StatusID        = 8;
                    db.Entry(checkDocument).State = System.Data.Entity.EntityState.Modified;
                    db.SaveChanges();
                }
            }
            catch (Exception e)
            {
                result.msg   = e.Message;
                result.error = 1;
            }

            return(result);
        }
Ejemplo n.º 2
0
        public ResultInfo CancelTakeMailer(string user, UpdateTakeMailerReceive info)
        {
            var result = new ResultInfo()
            {
                error = 0,
                msg   = "success"
            };
            var checkUser = db.BS_Employees.Where(p => p.UserLogin == user).FirstOrDefault();

            if (checkUser == null)
            {
                return(new ResultInfo()
                {
                    error = 1,
                    msg = "Sai thông tin"
                });
            }
            try
            {
                var checkDocument = db.MM_TakeMailers.Find(info.documentId);

                if (checkDocument == null)
                {
                    throw new Exception("Sai thông tin");
                }


                var checkMailer = db.MM_Mailers.Find(info.mailers);

                var findDetail = db.MM_TakeDetails.Where(p => p.DocumentID == checkDocument.DocumentID && p.MailerID == info.mailers).FirstOrDefault();


                if (findDetail == null || checkMailer == null)
                {
                    throw new Exception("Sai thông tin");
                }

                findDetail.StatusID        = 10;
                db.Entry(findDetail).State = System.Data.Entity.EntityState.Modified;

                //
                checkMailer.CurrentStatusID = 10;
                checkMailer.LastUpdateDate  = DateTime.Now;
                db.Entry(checkMailer).State = System.Data.Entity.EntityState.Modified;
                db.SaveChanges();

                HandleHistory.AddTracking(10, info.mailers, checkMailer.CurrentPostOfficeID, "KHÁCH HÀNG YÊU CẦU HỦY KHI ĐI LẤY HÀNG");

                var checkCount = db.TAKEMAILER_GETDETAILs(checkDocument.DocumentID).Where(p => p.CurrentStatusID == 7).ToList();

                if (checkCount.Count() == 0)
                {
                    checkDocument.StatusID        = 8;
                    db.Entry(checkDocument).State = System.Data.Entity.EntityState.Modified;
                    db.SaveChanges();
                }
            }
            catch (Exception e)
            {
                result.msg   = e.Message;
                result.error = 1;
            }

            return(result);
        }