コード例 #1
0
        public JsonResult NewEntry(AttachmentData data)
        {
            if (!Utils.Utils.GetPermission("SHOW_SELL_ATTACHMENTS"))
            {
                return(Json(0));
            }

            using (DataContext _db = new DataContext())
            {
                using (DbContextTransaction tran = _db.Database.BeginTransaction(IsolationLevel.Snapshot))
                {
                    try
                    {
                        if (data.code != null && data.code != "")
                        {
                            Customer cust = _db.Customers.Where(c => c.Code == data.code).FirstOrDefault();
                            //if (user_id != 0)
                            //{
                            //    cust.UserId = user_id;
                            //    _db.Entry(cust).State = EntityState.Modified;
                            //}
                            if (cust != null)
                            {
                                if (!_db.CustomerSellAttachments.Any(a => a.CustomerID == cust.Id))
                                {
                                    List <CustomerSellAttachments> new_attachments = new List <CustomerSellAttachments>();
                                    foreach (var item in data.attachmentVals)
                                    {
                                        if (item.count > 0)
                                        {
                                            new_attachments.Add(new CustomerSellAttachments {
                                                AttachmentID = item.id, Count = item.count, CustomerID = cust.Id
                                            });
                                        }
                                    }

                                    if (new_attachments.Count > 0)
                                    {
                                        _db.CustomerSellAttachments.AddRange(new_attachments);
                                        _db.SaveChanges();

                                        tran.Commit();
                                        return(Json(1));
                                    }
                                }
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        tran.Rollback();
                        return(Json(0));
                    }
                }
            }
            return(Json(0));
        }
コード例 #2
0
        public JsonResult NewEntryEdit(AttachmentData data, int diler_id)
        {
            if (!Utils.Utils.GetPermission("SHOW_SELL_ATTACHMENTS"))
            {
                return(Json(0));
            }

            using (DataContext _db = new DataContext())
            {
                using (DbContextTransaction tran = _db.Database.BeginTransaction(IsolationLevel.Snapshot))
                {
                    try
                    {
                        if (data.code != null && data.code != "")
                        {
                            Customer cust   = _db.Customers.Where(c => c.Code == data.code).FirstOrDefault();
                            DateTime dateTo = new DateTime();
                            dateTo = dateTo = Utils.Utils.GetRequestDate(Request["dt_to"], false);
                            var datefrom = _db.CustomerSellAttachments.Where(a => a.CustomerID == cust.Id && a.Diler_Id == diler_id).Select(s => s.Tdate).FirstOrDefault();
                            if (datefrom.ToString("dd-MM-yyy") == dateTo.ToString("dd-MM-yyy"))
                            {
                                return(Json(0));
                            }
                            if (cust != null)
                            {
                                List <CustomerSellAttachments> new_attachments = new List <CustomerSellAttachments>();
                                foreach (var item in data.attachmentVals)
                                {
                                    if (item.count > 0)
                                    {
                                        short verify_status = 0;
                                        var   attachment    = 0;
                                        if (_db.CustomerSellAttachments.Any(a => a.CustomerID == cust.Id && a.Diler_Id == diler_id))
                                        {
                                            verify_status = _db.CustomerSellAttachments.Where(a => a.CustomerID == cust.Id && a.Diler_Id == diler_id).FirstOrDefault().VerifyStatus;
                                            verify_status = verify_status == 2 || verify_status == 1 ? (short)1 : (short)0;
                                            var attachments = _db.CustomerSellAttachments.Where(a => a.CustomerID == cust.Id && a.Diler_Id == diler_id).ToList();
                                            attachments.ForEach(a => a.VerifyStatus     = verify_status);
                                            attachments.ForEach(a => _db.Entry(a).State = EntityState.Modified);
                                        }
                                        new_attachments.Add(new CustomerSellAttachments {
                                            AttachmentID = item.id, Count = item.count, CustomerID = cust.Id, Diler_Id = diler_id, VerifyStatus = verify_status
                                        });
                                    }
                                }
                                var promo = _db.Database.SqlQuery <int>(@"Select sp.package_id from book.Cards as c
                                                                            inner join book.Customers as cu on cu.id=c.customer_id
                                                                            inner join doc.Subscribes as s on s.card_id=c.id
                                                                            inner join doc.SubscriptionPackages as sp on sp.subscription_id=s.id where cu.code='" + data.code + "' and sp.package_id=304086").FirstOrDefault();
                                if (data.temporarily == 1)
                                {
                                    new_attachments.ToList().ForEach(a => a.VerifyStatus = 6);
                                    new_attachments.ToList().ForEach(a => a.status       = SellAttachmentStatus.temporary_use);
                                }
                                if (promo == 304086)
                                {
                                    new_attachments.ToList().ForEach(a => a.VerifyStatus = 5);
                                    new_attachments.ToList().ForEach(a => a.status       = SellAttachmentStatus.temporary_use);
                                }
                                if (new_attachments.Count > 0)
                                {
                                    _db.CustomerSellAttachments.AddRange(new_attachments);
                                    _db.SaveChanges();

                                    //if (data.temporarily == 1)
                                    //{
                                    //    CustomerSellAttachments customerSell = _db.CustomerSellAttachments.Where(c => c.CustomerID == _db.Customers.Where(cc => cc.Code == data.code).FirstOrDefault().Id).FirstOrDefault();
                                    //    customerSell.status = SellAttachmentStatus.temporary_use;
                                    //    customerSell.VerifyStatus = 5;
                                    //    _db.Entry(customerSell).State = EntityState.Modified;
                                    //    _db.SaveChanges();
                                    //}

                                    tran.Commit();
                                    return(Json(1));
                                }
                                //}
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        tran.Rollback();
                        return(Json(0));
                    }
                }
            }
            return(Json(0));
        }
コード例 #3
0
        public JsonResult UpdateEntryEdit(AttachmentData data, string date)
        {
            if (!Utils.Utils.GetPermission("SHOW_SELL_ATTACHMENTS"))
            {
                return(Json(0));
            }

            using (DataContext _db = new DataContext())
            {
                using (DbContextTransaction tran = _db.Database.BeginTransaction(IsolationLevel.Snapshot))
                {
                    try
                    {
                        if (data.customer_id == 0)
                        {
                            Customer cust = _db.Customers.Where(c => c.Code == data.code).FirstOrDefault();
                            data.customer_id = cust.Id;
                        }
                        if (data.temporarily == 1)
                        {
                            Customer cust_temp = _db.Customers.Where(c => c.Code == data.code).FirstOrDefault();
                            cust_temp.temporary_use = 1;
                        }
                        if (data.code != null && data.code != "")
                        {
                            //Customer cust = _db.Customers.Where(c => c.Code == data.code).FirstOrDefault();
                            List <CustomerSellAttachments> cur_attachs_date = _db.CustomerSellAttachments.Where(a => a.CustomerID == data.customer_id && a.Diler_Id == data.diller_id).ToList();
                            List <CustomerSellAttachments> cur_attachs      = new List <CustomerSellAttachments>();
                            foreach (var item in cur_attachs_date)
                            {
                                if (item.Tdate.ToString("dd-MM-yyy") == date && item.CustomerID == data.customer_id && item.Diler_Id == data.diller_id)
                                {
                                    cur_attachs.Add(item);
                                }
                            }
                            var customerSellAttachs = from custAttachs in cur_attachs
                                                      group custAttachs by custAttachs.AttachmentID into cGroup
                                                      select new
                            {
                                Key             = cGroup.Key,
                                customerAttachs = cGroup
                            };

                            foreach (var item in data.attachmentVals)
                            {
                                if (cur_attachs.Any(a => a.AttachmentID == item.id))
                                {
                                    foreach (var group in customerSellAttachs)
                                    {
                                        if (group.customerAttachs.FirstOrDefault().AttachmentID == item.id && group.customerAttachs.Select(a => a.Count).Sum() == item.count)
                                        {
                                            continue;
                                        }

                                        if (group.customerAttachs.FirstOrDefault().AttachmentID == item.id)
                                        {
                                            short verify_status = cur_attachs.FirstOrDefault().VerifyStatus == 2 || cur_attachs.FirstOrDefault().VerifyStatus == (short)1 ? (short)1 : (short)0;
                                            if (item.count > 0)
                                            {
                                                _db.CustomerSellAttachments.Add(new CustomerSellAttachments()
                                                {
                                                    Tdate        = DateTime.Now,
                                                    AttachmentID = group.customerAttachs.FirstOrDefault().AttachmentID,
                                                    Count        = item.count,
                                                    CustomerID   = group.customerAttachs.FirstOrDefault().CustomerID,
                                                    Diler_Id     = group.customerAttachs.FirstOrDefault().Diler_Id,
                                                    VerifyStatus = verify_status,
                                                    status       = group.customerAttachs.FirstOrDefault().status
                                                });

                                                cur_attachs.ToList().ForEach(a => a.VerifyStatus     = verify_status);
                                                cur_attachs.ToList().ForEach(a => _db.Entry(a).State = EntityState.Modified);
                                                cur_attachs.Remove(group.customerAttachs.Select(s => s).FirstOrDefault());
                                                _db.CustomerSellAttachments.RemoveRange(group.customerAttachs);
                                                _db.SaveChanges();
                                            }
                                            else if (item.count == 0)
                                            {
                                                cur_attachs.ToList().ForEach(a => a.VerifyStatus     = verify_status);
                                                cur_attachs.ToList().ForEach(a => _db.Entry(a).State = EntityState.Modified);
                                                cur_attachs.Remove(group.customerAttachs.Select(s => s).FirstOrDefault());
                                                _db.CustomerSellAttachments.RemoveRange(group.customerAttachs);
                                                _db.SaveChanges();
                                            }
                                        }
                                    }
                                }
                                else
                                {
                                    if (item.count > 0)
                                    {
                                        var   status        = customerSellAttachs.Select(s => s.customerAttachs.Where(a => a.CustomerID == data.customer_id).Select(ss => ss.status).FirstOrDefault()).FirstOrDefault();
                                        short verify_status = 0;
                                        //if (cur_attachs.Any(a => a.AttachmentID == item.id))
                                        {
                                            verify_status = cur_attachs.FirstOrDefault().VerifyStatus == 2 || cur_attachs.FirstOrDefault().VerifyStatus == (short)1 ? (short)1 : (short)0;
                                            cur_attachs.ToList().ForEach(a => a.VerifyStatus     = verify_status);
                                            cur_attachs.ToList().ForEach(a => _db.Entry(a).State = EntityState.Modified);
                                        }
                                        _db.CustomerSellAttachments.Add(new CustomerSellAttachments()
                                        {
                                            Tdate        = DateTime.ParseExact(date, "dd-MM-yyyy", CultureInfo.InvariantCulture),
                                            AttachmentID = item.id,
                                            Count        = item.count,
                                            CustomerID   = data.customer_id,
                                            Diler_Id     = data.diller_id,
                                            VerifyStatus = verify_status,
                                            status       = status
                                        });

                                        _db.SaveChanges();
                                    }
                                }
                            }
                            if (data.temporarily == 1)
                            {
                                CustomerSellAttachments customerSell = _db.CustomerSellAttachments.Where(c => c.CustomerID == data.customer_id).FirstOrDefault();
                                customerSell.status           = SellAttachmentStatus.temporary_use;
                                customerSell.VerifyStatus     = 6;
                                _db.Entry(customerSell).State = EntityState.Modified;
                                _db.SaveChanges();
                            }
                            _db.SaveChanges();

                            tran.Commit();
                            return(Json(1));
                        }
                    }
                    catch (Exception ex)
                    {
                        tran.Rollback();
                        return(Json(0));
                    }
                }
            }
            return(Json(0));
        }
コード例 #4
0
        public JsonResult UpdateEntry(AttachmentData data)
        {
            if (!Utils.Utils.GetPermission("SHOW_SELL_ATTACHMENTS"))
            {
                return(Json(0));
            }

            using (DataContext _db = new DataContext())
            {
                using (DbContextTransaction tran = _db.Database.BeginTransaction(IsolationLevel.Snapshot))
                {
                    try
                    {
                        //if (data.customer_id == 0)
                        //{
                        //    Customer cust = _db.Customers.Where(c => c.Code == data.code).FirstOrDefault();
                        //    data.customer_id = cust.Id;
                        //}
                        if (data.code != null && data.code != "")
                        {
                            //Customer cust = _db.Customers.Where(c => c.Code == data.code).FirstOrDefault();
                            List <CustomerSellAttachments> cur_attachs = _db.CustomerSellAttachments.Where(a => a.CustomerID == data.customer_id && a.Diler_Id == data.diller_id).ToList();
                            var customerSellAttachs = from custAttachs in cur_attachs
                                                      group custAttachs by custAttachs.AttachmentID into cGroup
                                                      select new
                            {
                                Key             = cGroup.Key,
                                customerAttachs = cGroup
                            };

                            foreach (var item in data.attachmentVals)
                            {
                                if (cur_attachs.Any(a => a.AttachmentID == item.id))
                                {
                                    foreach (var group in customerSellAttachs)
                                    {
                                        if (group.customerAttachs.FirstOrDefault().AttachmentID == item.id && group.customerAttachs.Select(a => a.Count).Sum() == item.count)
                                        {
                                            continue;
                                        }

                                        if (group.customerAttachs.FirstOrDefault().AttachmentID == item.id)
                                        {
                                            short verify_status = cur_attachs.FirstOrDefault().VerifyStatus == 2 || cur_attachs.FirstOrDefault().VerifyStatus == (short)1 ? (short)1 : (short)0;
                                            if (item.count > 0)
                                            {
                                                _db.CustomerSellAttachments.Add(new CustomerSellAttachments()
                                                {
                                                    Tdate        = DateTime.Now,
                                                    AttachmentID = group.customerAttachs.FirstOrDefault().AttachmentID,
                                                    Count        = item.count,
                                                    CustomerID   = group.customerAttachs.FirstOrDefault().CustomerID,
                                                    Diler_Id     = group.customerAttachs.FirstOrDefault().Diler_Id,
                                                    VerifyStatus = verify_status
                                                });

                                                cur_attachs.ToList().ForEach(a => a.VerifyStatus     = verify_status);
                                                cur_attachs.ToList().ForEach(a => _db.Entry(a).State = EntityState.Modified);

                                                _db.CustomerSellAttachments.RemoveRange(group.customerAttachs);
                                                _db.SaveChanges();
                                            }
                                            else if (item.count == 0)
                                            {
                                                cur_attachs.ToList().ForEach(a => a.VerifyStatus     = verify_status);
                                                cur_attachs.ToList().ForEach(a => _db.Entry(a).State = EntityState.Modified);

                                                _db.CustomerSellAttachments.RemoveRange(group.customerAttachs);
                                                _db.SaveChanges();
                                            }
                                        }
                                    }
                                }
                                else
                                {
                                    if (item.count > 0)
                                    {
                                        short verify_status = 0;
                                        //if (cur_attachs.Any(a => a.AttachmentID == item.id))
                                        {
                                            verify_status = cur_attachs.FirstOrDefault().VerifyStatus == 2 || cur_attachs.FirstOrDefault().VerifyStatus == (short)1 ? (short)1 : (short)0;
                                            cur_attachs.ToList().ForEach(a => a.VerifyStatus     = verify_status);
                                            cur_attachs.ToList().ForEach(a => _db.Entry(a).State = EntityState.Modified);
                                        }
                                        _db.CustomerSellAttachments.Add(new CustomerSellAttachments()
                                        {
                                            Tdate        = DateTime.Now,
                                            AttachmentID = item.id,
                                            Count        = item.count,
                                            CustomerID   = data.customer_id,
                                            Diler_Id     = data.diller_id,
                                            VerifyStatus = verify_status
                                        });

                                        _db.SaveChanges();
                                    }
                                }
                            }

                            _db.SaveChanges();

                            tran.Commit();
                            return(Json(1));
                        }
                    }
                    catch (Exception ex)
                    {
                        tran.Rollback();
                        return(Json(0));
                    }
                }
            }
            return(Json(0));
        }