Пример #1
0
        public static PostPublic Insert(PostPublic data)
        {
            using (var con = new inventorymanagementEntities())
            {
                con.PostPublics.Add(data);
                con.SaveChanges();

                return(data);
            }
        }
Пример #2
0
 public static int Insert(tbl_RefundGoods refund)
 {
     using (var con = new inventorymanagementEntities())
     {
         con.tbl_RefundGoods.Add(refund);
         con.SaveChanges();
         int kq = refund.ID;
         return(kq);
     }
 }
Пример #3
0
        /// <summary>
        /// Cập nhật lại các thông tin thay đổi mới
        /// </summary>
        /// <param name="scheduleNews"></param>
        /// <returns></returns>
        public static List <CronJobProductStatu> updateScheduleProductStatus(List <CronJobProductStatu> scheduleNews)
        {
            try
            {
                using (var con = new inventorymanagementEntities())
                {
                    var index = 0;

                    foreach (var item in scheduleNews)
                    {
                        index++;

                        var scheduleOld = con.CronJobProductStatus.Where(x => x.ID == item.ID).FirstOrDefault();

                        if (scheduleOld != null)
                        {
                            scheduleOld.Status       = item.Status;
                            scheduleOld.Note         = item.Note;
                            scheduleOld.ModifiedDate = item.ModifiedDate;
                        }

                        if (index >= 100)
                        {
                            con.SaveChanges();
                            index = 0;
                        }
                    }

                    if (index > 0)
                    {
                        con.SaveChanges();
                        index = 0;
                    }

                    return(scheduleNews);
                }
            }
            catch (Exception ex)
            {
                Log.Instance().Error("Update the schedule list", ex);
                throw;
            }
        }
Пример #4
0
        public static ProductTag insert(ProductTag data)
        {
            using (var con = new inventorymanagementEntities())
            {
                con.ProductTags.Add(data);
                con.SaveChanges();

                return(data);
            }
        }
Пример #5
0
        public static NotifyNew Insert(NotifyNew data)
        {
            using (var con = new inventorymanagementEntities())
            {
                con.NotifyNews.Add(data);
                con.SaveChanges();

                return(data);
            }
        }
Пример #6
0
        public static tbl_Post Insert(tbl_Post data)
        {
            using (var con = new inventorymanagementEntities())
            {
                con.tbl_Post.Add(data);
                con.SaveChanges();

                return(data);
            }
        }
Пример #7
0
        public static string Insert(int AgentID, int OrderID, string SKU, int ProductID, int ProductVariableID, string ProductVariableDescrition, double Quantity,
                                    double Price, int Status, double DiscountPrice, int ProductType, DateTime CreatedDate, string CreatedBy, bool IsCount)
        {
            using (var con = new inventorymanagementEntities())
            {
                #region Cập nhật thôn tin giá vốn
                Nullable <double> cogs = null;

                #region Sản phẩm đơn gian
                if (ProductType == 1)
                {
                    cogs = con.tbl_Product
                           .Where(x => x.ID == ProductID)
                           .Select(x => x.CostOfGood.HasValue ? x.CostOfGood.Value : 0)
                           .SingleOrDefault();
                }
                #endregion

                #region Sản phẩm biến thể
                if (ProductType == 2)
                {
                    cogs = con.tbl_ProductVariable
                           .Where(x => x.ID == ProductVariableID)
                           .Select(x => x.CostOfGood.HasValue ? x.CostOfGood.Value : 0)
                           .SingleOrDefault();
                }
                #endregion
                #endregion

                #region Khởi tạo chi tiết đơn hàng
                tbl_OrderDetail ui = new tbl_OrderDetail();
                ui.AgentID                   = AgentID;
                ui.OrderID                   = OrderID;
                ui.SKU                       = SKU;
                ui.ProductID                 = ProductID;
                ui.ProductVariableID         = ProductVariableID;
                ui.ProductVariableDescrition = ProductVariableDescrition;
                ui.Quantity                  = Quantity;
                ui.Price                     = Convert.ToDouble(Price);
                ui.Status                    = Status;
                ui.DiscountPrice             = DiscountPrice;
                ui.ProductType               = ProductType;
                ui.CreatedDate               = CreatedDate;
                ui.CreatedBy                 = CreatedBy;
                ui.ModifiedDate              = CreatedDate;
                ui.ModifiedBy                = CreatedBy;
                ui.IsCount                   = IsCount;
                ui.CostOfGood                = cogs.HasValue ? Convert.ToDecimal(cogs.Value) : 0;
                con.tbl_OrderDetail.Add(ui);
                int kq = con.SaveChanges();
                #endregion

                return(kq.ToString());
            }
        }
Пример #8
0
        public static bool deleteAll(int orderID)
        {
            using (var con = new inventorymanagementEntities())
            {
                var fees = con.Fees.Where(x => x.OrderID == orderID);
                con.Fees.RemoveRange(fees);
                con.SaveChanges();
            }

            return(true);
        }
 public static int Insert(string Title, int ParentID)
 {
     using (var dbe = new inventorymanagementEntities())
     {
         tbl_PostCategory ui = new tbl_PostCategory();
         ui.Title = Title;
         ui.ParentID = ParentID;
         dbe.tbl_PostCategory.Add(ui);
         int kq = dbe.SaveChanges();
         return ui.ID;
     }
 }
Пример #10
0
 public static int Insert(string Name, int ParentID)
 {
     using (var dbe = new inventorymanagementEntities())
     {
         PostCategory ui = new PostCategory();
         ui.Name     = Name;
         ui.ParentID = ParentID;
         dbe.PostCategories.Add(ui);
         int kq = dbe.SaveChanges();
         return(ui.ID);
     }
 }
Пример #11
0
        public static List <ProductTag> update(int productID, List <ProductTag> prodTags)
        {
            using (var con = new inventorymanagementEntities())
            {
                var tagDB = con.ProductTags
                            .Where(x => x.ProductID == productID)
                            .Where(x => x.ProductVariableID == 0)
                            .ToList();

                var tagOld = tagDB
                             .Join(
                    prodTags,
                    tdb => tdb.TagID,
                    pt => pt.TagID,
                    (tdb, pt) => tdb
                    )
                             .ToList();

                var tagDelete = tagDB.Except(tagOld).ToList();
                if (tagDelete.Count > 0)
                {
                    con.ProductTags.RemoveRange(tagDelete);
                    con.SaveChanges();
                    tagDB = tagDB.Except(tagDelete).ToList();
                }

                var tagInsert = prodTags
                                .Where(x => !tagOld.Any(y => y.ProductID == x.ProductID && y.TagID == x.TagID))
                                .ToList();

                if (tagInsert.Count > 0)
                {
                    con.ProductTags.AddRange(tagInsert);
                    con.SaveChanges();
                    tagDB.AddRange(tagInsert);
                }

                return(tagDB);
            }
        }
Пример #12
0
        public static void Insert(tbl_OrderDetail orderDetail)
        {
            using (var con = new inventorymanagementEntities())
            {
                #region Cập nhật thôn tin giá vốn
                Nullable <double> cogs = null;

                #region Sản phẩm đơn gian
                if (orderDetail.ProductType == 1)
                {
                    cogs = con.tbl_Product
                           .Where(x => x.ID == orderDetail.ProductID)
                           .Select(x => x.CostOfGood.HasValue ? x.CostOfGood.Value : 0)
                           .SingleOrDefault();
                }
                #endregion

                #region Sản phẩm biến thể
                if (orderDetail.ProductType == 2)
                {
                    cogs = con.tbl_ProductVariable
                           .Where(x => x.ID == orderDetail.ProductVariableID)
                           .Select(x => x.CostOfGood.HasValue ? x.CostOfGood.Value : 0)
                           .SingleOrDefault();
                }
                #endregion
                #endregion

                #region Khởi tạo chi tiết đơn hàng
                tbl_OrderDetail ui = new tbl_OrderDetail();
                ui.AgentID                   = orderDetail.AgentID;
                ui.OrderID                   = orderDetail.OrderID;
                ui.SKU                       = orderDetail.SKU;
                ui.ProductID                 = orderDetail.ProductID;
                ui.ProductVariableID         = orderDetail.ProductVariableID;
                ui.ProductVariableDescrition = orderDetail.ProductVariableDescrition;
                ui.Quantity                  = orderDetail.Quantity;
                ui.Price                     = orderDetail.Price;
                ui.Status                    = orderDetail.Status;
                ui.DiscountPrice             = orderDetail.DiscountPrice;
                ui.ProductType               = orderDetail.ProductType;
                ui.CreatedDate               = orderDetail.CreatedDate;
                ui.CreatedBy                 = orderDetail.CreatedBy;
                ui.ModifiedDate              = orderDetail.ModifiedDate;
                ui.ModifiedBy                = orderDetail.ModifiedBy;
                ui.IsCount                   = orderDetail.IsCount;
                ui.CostOfGood                = cogs.HasValue ? Convert.ToDecimal(cogs.Value) : 0;
                con.tbl_OrderDetail.Add(ui);
                con.SaveChanges();
                #endregion
            }
        }
Пример #13
0
        public static void Delete(int registerID)
        {
            using (var con = new inventorymanagementEntities())
            {
                var register = con.RegisterProducts.Where(x => x.ID == registerID).FirstOrDefault();

                if (register != null)
                {
                    con.RegisterProducts.Remove(register);
                    con.SaveChanges();
                }
            }
        }
Пример #14
0
        public static void cancel(int postOfficeID)
        {
            using (var con = new inventorymanagementEntities())
            {
                var postOffice = con.DeliveryPostOffices.Where(x => x.ID == postOfficeID).FirstOrDefault();

                if (postOffice != null)
                {
                    postOffice.OrderStatus = (int)OrderStatus.Spam;
                    con.SaveChanges();
                }
            }
        }
Пример #15
0
 public static tbl_WhiteDomain insert(string Domain, string Created)
 {
     using (var db = new inventorymanagementEntities())
     {
         tbl_WhiteDomain wd = new tbl_WhiteDomain();
         wd.Domain      = Domain;
         wd.IsHidden    = false;
         wd.CreatedBy   = Created;
         wd.CreatedDate = DateTime.Now;
         db.tbl_WhiteDomain.Add(wd);
         db.SaveChanges();
         return(wd);
     }
 }
 public static string Insert(string CustomerLevelName, bool IsHidden, DateTime CreatedDate, string CreatedBy)
 {
     using (var dbe = new inventorymanagementEntities())
     {
         tbl_CustomerLevel ui = new tbl_CustomerLevel();
         ui.CustomerLevelName = CustomerLevelName;
         ui.IsHidden          = IsHidden;
         ui.CreatedDate       = CreatedDate;
         ui.CreatedBy         = CreatedBy;
         dbe.tbl_CustomerLevel.Add(ui);
         int kq = dbe.SaveChanges();
         return(kq.ToString());
     }
 }
Пример #17
0
        private void _createCheckWarehouseDetail(List <CheckWarehouseDetail> data)
        {
            using (var con = new inventorymanagementEntities())
            {
                var totalInserts = (int)Math.Ceiling(data.Count / 100D);

                for (int i = 0; i < totalInserts; i++)
                {
                    var details = data.Skip(i * 100).Take(100).ToList();
                    con.CheckWarehouseDetails.AddRange(details);
                    con.SaveChanges();
                }
            }
        }
Пример #18
0
        public static bool updateBankOfOrder(int OrderID, int AccBankID)
        {
            using (var con = new inventorymanagementEntities())
            {
                var old = con.BankTransfers.Where(x => x.OrderID == OrderID).SingleOrDefault();
                if (old != null)
                {
                    old.AccBankID = AccBankID;
                    con.SaveChanges();
                }
            }

            return(true);
        }
Пример #19
0
        public static string Insert(string CustomerName, string CustomerPhone, string CustomerAddress, string CustomerEmail, int CustomerLevelID, int Status,
                                    DateTime CreatedDate, string CreatedBy, bool IsHidden, string Zalo, string Facebook, string Note, string Nick, string Avatar = "", int ShippingType = 0, int PaymentType = 0, int TransportCompanyID = 0, int TransportCompanySubID = 0, string CustomerPhone2 = "", int ProvinceID = 0, int DistrictID = 0, int WardID = 0)
        {
            using (var dbe = new inventorymanagementEntities())
            {
                tbl_Customer ui = new tbl_Customer();
                ui.CustomerName          = CustomerName;
                ui.UnSignedName          = UnSign.convert(CustomerName);
                ui.CustomerPhone         = CustomerPhone;
                ui.CustomerAddress       = CustomerAddress;
                ui.CustomerEmail         = CustomerEmail;
                ui.CustomerLevelID       = CustomerLevelID;
                ui.Status                = Status;
                ui.CreatedDate           = CreatedDate;
                ui.CreatedBy             = CreatedBy;
                ui.IsHidden              = IsHidden;
                ui.Zalo                  = Zalo;
                ui.Facebook              = Facebook;
                ui.Note                  = Note;
                ui.Nick                  = Nick;
                ui.UnSignedNick          = UnSign.convert(Nick);
                ui.Avatar                = Avatar;
                ui.ShippingType          = ShippingType;
                ui.PaymentType           = PaymentType;
                ui.TransportCompanyID    = TransportCompanyID;
                ui.TransportCompanySubID = TransportCompanySubID;
                ui.CustomerPhone2        = CustomerPhone2;
                ui.ProvinceID            = ProvinceID;
                ui.DistrictId            = DistrictID;
                ui.WardId                = WardID;

                try
                {
                    dbe.tbl_Customer.Add(ui);
                    dbe.SaveChanges();
                }
                catch (DbEntityValidationException dbEx)
                {
                    foreach (var validationErrors in dbEx.EntityValidationErrors)
                    {
                        foreach (var validationError in validationErrors.ValidationErrors)
                        {
                            System.Console.WriteLine("Property: {0} Error: {1}", validationError.PropertyName, validationError.ErrorMessage);
                        }
                    }
                }
                int kq = ui.ID;
                return(kq.ToString());
            }
        }
Пример #20
0
        public static void updateSKU(int ID, string newSKU)
        {
            using (var dbe = new inventorymanagementEntities())
            {
                var ui = dbe.tbl_ProductVariable.Where(a => a.ProductID == ID).ToList();
                ui.ForEach(a =>
                {
                    a.SKU       = a.SKU.Replace(a.ParentSKU, newSKU);
                    a.ParentSKU = newSKU;
                });

                dbe.SaveChanges();
            }
        }
Пример #21
0
 public static string Insert(int PostID, string Image, string CreatedBy, DateTime CreatedDate)
 {
     using (var dbe = new inventorymanagementEntities())
     {
         tbl_PostImage ui = new tbl_PostImage();
         ui.PostID      = PostID;
         ui.Image       = Image;
         ui.CreatedDate = CreatedDate;
         ui.CreatedBy   = CreatedBy;
         dbe.tbl_PostImage.Add(ui);
         int kq = dbe.SaveChanges();
         return(kq.ToString());
     }
 }
Пример #22
0
 public static string deleteAll(int ProductID)
 {
     using (var dbe = new inventorymanagementEntities())
     {
         List <tbl_ProductImage> ui = dbe.tbl_ProductImage.Where(o => o.ProductID == ProductID).ToList();
         if (ui != null)
         {
             dbe.tbl_ProductImage.RemoveRange(ui);
             int kq = dbe.SaveChanges();
             return(kq.ToString());
         }
         return("0");
     }
 }
Пример #23
0
 public static string Delete(int ID)
 {
     using (var dbe = new inventorymanagementEntities())
     {
         var ui = dbe.tbl_ProductImage.Where(o => o.ID == ID).FirstOrDefault();
         if (ui != null)
         {
             dbe.tbl_ProductImage.Remove(ui);
             int kq = dbe.SaveChanges();
             return(kq.ToString());
         }
         return("0");
     }
 }
Пример #24
0
 public static string UpdateIsCount(int ID, bool isCount)
 {
     using (var dbe = new inventorymanagementEntities())
     {
         var ui = dbe.tbl_OrderDetail.Where(o => o.ID == ID).FirstOrDefault();
         if (ui != null)
         {
             ui.IsCount = isCount;
             int kq = dbe.SaveChanges();
             return(kq.ToString());
         }
         return("0");
     }
 }
Пример #25
0
        /// <summary>
        /// Cập nhật lại trạng thái và giờ start
        /// </summary>
        /// <param name="name"></param>
        /// <param name="cronExpression"></param>
        /// <param name="status"></param>
        /// <returns></returns>
        public static IM_PJ.Models.CronJob update(IM_PJ.Models.CronJob cronNew)
        {
            using (var con = new inventorymanagementEntities())
            {
                var cronJOB = con.CronJobs
                              .Where(x => x.Name.Trim().ToLower() == cronNew.Name.Trim().ToLower())
                              .FirstOrDefault();

                if (cronJOB != null)
                {
                    // Cập nhật lại trạng thái và giờ start
                    cronJOB.CronExpression = cronNew.CronExpression;
                    cronJOB.Status         = cronNew.Status;
                    cronJOB.RunAllProduct  = cronNew.RunAllProduct;
                    cronJOB.MinProduct     = cronNew.MinProduct;
                    cronJOB.ModifiedDate   = DateTime.Now;

                    con.SaveChanges();

                    // Xóa task củ
                    if (cronJOB.JobID.HasValue)
                    {
                        CronManager.RemoveJob(cronJOB.JobID.Value);
                    }

                    // Load lại cron job để cập nhật thông tin mới
                    var taskProductStatus = new CreateScheduleProductStatus();
                    CronManager.AddJob(taskProductStatus);

                    // Cập nhật lại JobID new
                    cronJOB.JobID = taskProductStatus.JobID;
                    con.SaveChanges();
                }

                return(cronJOB);
            }
        }
Пример #26
0
        public static bool updateQuantity(IList <UpdateQuantityModel> data)
        {
            try
            {
                using (var con = new inventorymanagementEntities())
                {
                    int?checkID = data.Select(x => x.checkID).FirstOrDefault();

                    if (!checkID.HasValue)
                    {
                        return(false);
                    }

                    var products = con.CheckWarehouseDetails
                                   .Where(x => x.CheckWarehouseID == checkID)
                                   .ToList();

                    var updateList = products
                                     .Join(
                        data,
                        cw => cw.ProductSKU,
                        d => d.sku,
                        (cw, d) =>
                    {
                        cw.QuantityNew  = d.quantity;
                        cw.ModifiedDate = d.updateDate;
                        cw.ModifiedBy   = d.staff;

                        return(cw);
                    }
                        )
                                     .ToList();

                    var total = (int)Math.Ceiling(updateList.Count / 100D);

                    for (int i = 0; i < total; i++)
                    {
                        var items = products.Skip(i * 100).Take(100).ToList();
                        con.SaveChanges();
                    }

                    return(true);
                }
            }
            catch (Exception)
            {
                return(false);
            }
        }
Пример #27
0
 public static tbl_Discount insert(int Quantity, int DiscountPerProduct, string CreatedBy)
 {
     using (var db = new inventorymanagementEntities())
     {
         tbl_Discount dc = new tbl_Discount();
         dc.Quantity           = Quantity;
         dc.DiscountPerProduct = DiscountPerProduct;
         dc.CreatedBy          = CreatedBy;
         dc.CreatedDate        = DateTime.Now;
         dc.IsHidden           = false;
         db.tbl_Discount.Add(dc);
         db.SaveChanges();
         return(dc);
     }
 }
Пример #28
0
 public static string UpdateSecurityCode(string SecurityCode)
 {
     using (var dbe = new inventorymanagementEntities())
     {
         var a = dbe.tbl_Config.Where(ac => ac.ID == 1).SingleOrDefault();
         if (a != null)
         {
             a.SecurityCode = PJUtils.Encrypt("scode", SecurityCode);
             dbe.Configuration.ValidateOnSaveEnabled = false;
             int kq = dbe.SaveChanges();
             return(kq.ToString());
         }
         return(null);
     }
 }
Пример #29
0
        public static void deleteRegisterProductSession(tbl_Account acc, string page = "danh-sach-nhap-hang")
        {
            using (var con = new inventorymanagementEntities())
            {
                var session = con.Sessions
                              .Where(x => x.AccountID == acc.ID)
                              .Where(x => x.Page.ToLower() == page.ToLower());

                if (session.Count() > 0)
                {
                    con.Sessions.RemoveRange(session);
                    con.SaveChanges();
                }
            }
        }
Пример #30
0
 public static string Insert(int ProductID, string ProductImage, bool IsHidden, DateTime CreatedDate, string CreatedBy)
 {
     using (var dbe = new inventorymanagementEntities())
     {
         tbl_ProductImage ui = new tbl_ProductImage();
         ui.ProductID    = ProductID;
         ui.ProductImage = ProductImage;
         ui.IsHidden     = IsHidden;
         ui.CreatedDate  = CreatedDate;
         ui.CreatedBy    = CreatedBy;
         dbe.tbl_ProductImage.Add(ui);
         int kq = dbe.SaveChanges();
         return(kq.ToString());
     }
 }