Пример #1
0
        public bool InsertOrUpdate(CMS_PolicyModels model, ref string msg)
        {
            var result = true;

            using (var cxt = new CMS_Context())
            {
                using (var trans = cxt.Database.BeginTransaction())
                {
                    try
                    {
                        if (string.IsNullOrEmpty(model.Id))
                        {
                        }
                        else
                        {
                        }
                        cxt.SaveChanges();
                        trans.Commit();
                    }
                    catch (Exception)
                    {
                        result = false;
                        msg    = "Vui lòng kiểm tra đường truyền";
                        trans.Rollback();
                    }
                    finally
                    {
                        cxt.Dispose();
                    }
                }
            }
            return(result);
        }
Пример #2
0
        public bool Delete(string Id, ref string msg)
        {
            var result = true;

            using (var cxt = new CMS_Context())
            {
                using (var trans = cxt.Database.BeginTransaction())
                {
                    try
                    {
                        var e = cxt.CMS_Companies.Find(Id);
                        cxt.SaveChanges();
                        trans.Commit();
                    }
                    catch (Exception ex)
                    {
                        result = false;
                        msg    = "Không thể xóa thể loại này";
                        trans.Rollback();
                    }
                    finally
                    {
                        cxt.Dispose();
                    }
                }
            }
            return(result);
        }
Пример #3
0
        public bool RemoveKeyFromGroup(string KeyId, string GroupKeyID, ref string msg)
        {
            var result = true;

            using (var _db = new CMS_Context())
            {
                using (var trans = _db.Database.BeginTransaction())
                {
                    try
                    {
                        /* add new record */
                        var checkRemove = _db.CMS_R_GroupKey_KeyWord.Where(o => o.KeyWordID == KeyId && o.GroupKeyID == GroupKeyID).FirstOrDefault();
                        checkRemove.Status      = (byte)Commons.EStatus.Deleted;
                        checkRemove.UpdatedDate = DateTime.Now;
                        _db.SaveChanges();
                        trans.Commit();
                    }
                    catch (Exception ex)
                    {
                        msg    = "Check connection, please!";
                        result = false;
                        trans.Rollback();
                    }
                    finally
                    {
                        _db.Dispose();
                    }
                }
            }
            return(result);
        }
Пример #4
0
        public bool CreateOrUpdate(CMS_NewsModels model, ref string msg)
        {
            var Result = true;

            using (var cxt = new CMS_Context())
            {
                using (var trans = cxt.Database.BeginTransaction())
                {
                    try
                    {
                        if (string.IsNullOrEmpty(model.Id))
                        {
                            var _Id = Guid.NewGuid().ToString();
                            var e   = new CMS_News
                            {
                                Id                = _Id,
                                Title             = model.Title,
                                Short_Description = model.Short_Description,
                                ImageURL          = model.ImageURL,
                                CreatedBy         = model.CreatedBy,
                                CreatedDate       = DateTime.Now,
                                Description       = model.Description,
                                UpdatedBy         = model.UpdatedBy,
                                UpdatedDate       = DateTime.Now,
                                IsActive          = model.IsActive
                            };
                            cxt.CMS_News.Add(e);
                        }
                        else
                        {
                            var e = cxt.CMS_News.Find(model.Id);
                            if (e != null)
                            {
                                e.Title             = model.Title;
                                e.Short_Description = model.Short_Description;
                                e.ImageURL          = model.ImageURL;
                                e.Description       = model.Description;
                                e.UpdatedBy         = model.UpdatedBy;
                                e.UpdatedDate       = DateTime.Now;
                                e.IsActive          = model.IsActive;
                            }
                        }
                        cxt.SaveChanges();
                        trans.Commit();
                    }
                    catch (Exception)
                    {
                        Result = false;
                        msg    = "Vui lòng kiểm tra đường truyền";
                        trans.Rollback();
                    }
                    finally
                    {
                        cxt.Dispose();
                    }
                }
            }
            return(Result);
        }
Пример #5
0
        public bool CreateOrUpdate(CMS_SimsModels model, ref string msg)
        {
            var result = true;

            using (var cxt = new CMS_Context())
            {
                using (var trans = cxt.Database.BeginTransaction())
                {
                    try
                    {
                        if (string.IsNullOrEmpty(model.Id))
                        {
                            var _Id = Guid.NewGuid().ToString();
                            var e   = new CMS_Sims
                            {
                                Id           = _Id,
                                OperatorName = model.OperatorName,
                                SimName      = model.SimName,
                                SimNumber    = model.SimNumber,
                                Status       = model.Status,
                                IsActive     = model.IsActive,
                                UpdatedBy    = model.UpdatedBy,
                                UpdatedDate  = DateTime.Now,
                                CreatedBy    = model.CreatedBy,
                                CreatedDate  = DateTime.Now
                            };
                            cxt.CMS_Sims.Add(e);
                        }
                        else
                        {
                            var e = cxt.CMS_Sims.Find(model.Id);
                            if (e != null)
                            {
                                e.OperatorName = model.OperatorName;
                                e.SimName      = model.SimName;
                                e.SimNumber    = model.SimNumber;
                                e.Status       = model.Status;
                                e.IsActive     = model.IsActive;
                                e.UpdatedDate  = DateTime.Now;
                                e.UpdatedBy    = model.UpdatedBy;
                            }
                        }
                        cxt.SaveChanges();
                        trans.Commit();
                    }
                    catch (Exception ex)
                    {
                        msg    = "Vui lòng kiểm tra đường truyền";
                        result = false;
                        trans.Rollback();
                    }
                    finally
                    {
                        cxt.Dispose();
                    }
                }
            }
            return(result);
        }
Пример #6
0
        public bool InsertFromExcel(CMS_MarketingModels model, ref string msg)
        {
            var result = true;

            using (var cxt = new CMS_Context())
            {
                using (var trans = cxt.Database.BeginTransaction())
                {
                    try
                    {
                        if (string.IsNullOrEmpty(model.Id))
                        {
                            var _Id = Guid.NewGuid().ToString();
                            model.Id = _Id;
                            var e = new CMS_Marketing
                            {
                                Id           = _Id,
                                CustomerId   = model.CustomerId,
                                CustomerName = model.CustomerName,
                                OperatorName = model.OperatorName,
                                RunTime      = model.RunTime.Value,
                                SendFrom     = model.SendFrom,
                                SendTo       = model.SendTo,
                                SMSContent   = model.SMSContent,
                                SMSPrice     = model.SMSPrice,
                                SMSType      = model.SMSType,
                                Status       = model.Status,
                                TimeInput    = model.TimeInput,
                                IsActive     = model.IsActive,
                                SMSRate      = model.SMSRate,
                                UpdatedBy    = model.UpdatedBy,
                                UpdatedDate  = DateTime.Now,
                                CreatedBy    = model.CreatedBy,
                                CreatedDate  = DateTime.Now,
                            };
                            cxt.CMS_Marketing.Add(e);
                            var customer = cxt.CMS_Customers.Where(x => x.Id.Equals(model.CustomerId)).FirstOrDefault();
                            customer.TotalCredit = customer.TotalCredit - model.SMSPrice;
                        }
                        cxt.SaveChanges();
                        trans.Commit();
                    }
                    catch (Exception ex)
                    {
                        msg    = "Vui lòng kiểm tra đường truyền";
                        result = false;
                        trans.Rollback();
                    }
                    finally
                    {
                        cxt.Dispose();
                    }
                }
            }
            return(result);
        }
Пример #7
0
 /// <summary>
 /// Protected Virtual Dispose method
 /// </summary>
 /// <param name="disposing"></param>
 protected virtual void Dispose(bool disposing)
 {
     if (!this.disposed)
     {
         if (disposing)
         {
             Debug.WriteLine("UnitOfWork is being disposed");
             _context.Dispose();
         }
     }
     this.disposed = true;
 }
Пример #8
0
        public List <CMS_MarketingModels> Import(string filePath, string empId, string empName, string empphone, ref string msg)
        {
            using (var cxt = new CMS_Context())
            {
                List <CMS_MarketingModels> listMessage = new List <CMS_MarketingModels>();
                try
                {
                    DataTable dtMarketing = _baseFactory.GetDataFromExcel(@filePath, 1);
                    //DataTable dtTime = _baseFactory.GetDataFromExcel(@filePath, 2);
                    decimal rate = GetSMSRate(cxt, (int)Commons.ConfigType.SMSMarketing);
                    for (int i = 0; i < dtMarketing.Rows.Count; i++)
                    {
                        string phone      = Convert.ToString(dtMarketing.Rows[i][0]);
                        string smsContent = Convert.ToString(dtMarketing.Rows[i][1]);
                        string subPhone   = phone.Substring(0, 2);
                        string subPhone1  = phone.Substring(0, 1);
                        if (!subPhone.Equals("84") && !subPhone1.Equals("0"))
                        {
                            phone = "84" + phone;
                        }

                        if (!string.IsNullOrEmpty(phone))
                        {
                            string smsConvert         = Commons.ConvertUnicodeToWithoutAccent(smsContent);
                            int    count2             = smsConvert.Length;
                            int    smsFee             = count2 / 80; // < 80 = 1sms
                            CMS_MarketingModels model = new CMS_MarketingModels()
                            {
                                CustomerId   = empId,
                                CustomerName = string.Format("{0} ({1})", empName, empphone),
                                CountMessage = count2,
                                SendTo       = phone,
                                SMSContent   = smsContent,
                                SMSType      = (int)Commons.SMSType.Marketing,
                                Status       = (int)Commons.SMSStatus.Sent,
                                SMSPrice     = (smsFee + 1) * rate,
                                SMSRate      = rate
                            };
                            listMessage.Add(model);
                        }
                    }
                }
                catch (Exception ex)
                {
                    NSLog.Logger.Error("Import marketing error: ", ex);
                }
                finally
                {
                    cxt.Dispose();
                }
                return(listMessage);
            }
        }
Пример #9
0
        public bool AddKeyToGroup(string KeyId, string GroupKeyID, ref string msg)
        {
            var result = true;

            using (var _db = new CMS_Context())
            {
                using (var trans = _db.Database.BeginTransaction())
                {
                    try
                    {
                        /* add new record */
                        var checkExist = _db.CMS_R_GroupKey_KeyWord.Where(o => o.KeyWordID == KeyId && o.GroupKeyID == GroupKeyID).FirstOrDefault();
                        if (checkExist != null)
                        {
                            if (checkExist.Status != (byte)Commons.EStatus.Active)
                            {
                                checkExist.Status      = (byte)Commons.EStatus.Active;
                                checkExist.UpdatedDate = DateTime.Now;
                            }
                        }
                        else /* add new */
                        {
                            var newGroupKey = new CMS_R_GroupKey_KeyWord()
                            {
                                ID          = Guid.NewGuid().ToString(),
                                GroupKeyID  = GroupKeyID,
                                KeyWordID   = KeyId,
                                Status      = (byte)Commons.EStatus.Active,
                                CreatedDate = DateTime.Now,
                                UpdatedDate = DateTime.Now,
                            };
                            _db.CMS_R_GroupKey_KeyWord.Add(newGroupKey);
                        }

                        _db.SaveChanges();
                        trans.Commit();
                    }
                    catch (Exception ex)
                    {
                        msg    = "Check connection, please!";
                        result = false;
                        trans.Rollback();
                    }
                    finally
                    {
                        _db.Dispose();
                    }
                }
            }
            return(result);
        }
Пример #10
0
        public bool InsertOrUpdate(CMS_PolicyModels model, ref string msg)
        {
            var result = true;

            using (var cxt = new CMS_Context())
            {
                using (var trans = cxt.Database.BeginTransaction())
                {
                    try
                    {
                        if (string.IsNullOrEmpty(model.Id))
                        {
                            var e = new CMS_Policy
                            {
                                Id          = Guid.NewGuid().ToString(),
                                CreatedBy   = model.CreatedBy,
                                CreatedDate = DateTime.Now,
                                Description = model.Description,
                                IsActive    = model.IsActive,
                                UpdatedBy   = model.UpdatedBy,
                                UpdatedDate = DateTime.Now
                            };
                            cxt.CMS_Policys.Add(e);
                        }
                        else
                        {
                            var e = cxt.CMS_Policys.Find(model.Id);
                            e.CreatedBy   = model.CreatedBy;
                            e.Description = model.Description;
                            e.IsActive    = model.IsActive;
                            e.UpdatedBy   = model.UpdatedBy;
                            e.UpdatedDate = DateTime.Now;
                        }
                        cxt.SaveChanges();
                        trans.Commit();
                    }
                    catch (Exception)
                    {
                        result = false;
                        msg    = "Vui lòng kiểm tra đường truyền";
                        trans.Rollback();
                    }
                    finally
                    {
                        cxt.Dispose();
                    }
                }
            }
            return(result);
        }
        public bool ChangeStatus(CMS_DepositTransactionsModel model, string userId)
        {
            var result = true;

            try
            {
                using (var cxt = new CMS_Context())
                {
                    using (var trans = cxt.Database.BeginTransaction())
                    {
                        try
                        {
                            var e = cxt.CMS_DepositTransactions.Where(x => x.Id.Equals(model.Id)).ToList();
                            e.ForEach(x =>
                            {
                                x.Status      = model.Status;
                                x.UpdatedDate = DateTime.Now;
                                x.UpdatedBy   = userId;
                            });
                            var c = cxt.CMS_Customers.Where(x => x.Id.Equals(model.CustomerId)).FirstOrDefault();
                            if (c != null)
                            {
                                c.TotalCredit += model.PackageSMS;// change after confirm
                                c.UpdatedBy    = userId;
                                c.UpdatedDate  = DateTime.Now;
                            }
                            cxt.SaveChanges();
                            trans.Commit();
                        }
                        catch (Exception ex)
                        {
                            NSLog.Logger.Error("ChangeStatusDepositTransaction", ex);
                            trans.Rollback();
                        }
                        finally
                        {
                            cxt.Dispose();
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                NSLog.Logger.Error("ChangeStatusDepositTransaction", ex);
            }
            return(result);
        }
Пример #12
0
        public bool UpdateSMSStatus(string id, int status, ref string msg)
        {
            var result = true;

            using (var cxt = new CMS_Context())
            {
                using (var trans = cxt.Database.BeginTransaction())
                {
                    try
                    {
                        if (!string.IsNullOrEmpty(id))
                        {
                            var e = cxt.CMS_Marketing.Find(id);
                            if (e != null)
                            {
                                e.Status      = status;
                                e.UpdatedDate = DateTime.Now;
                                e.UpdatedBy   = "GSM";
                                if (status.Equals((int)Commons.SMSStatus.Fail))
                                {
                                    var customer = cxt.CMS_Customers.Where(x => x.Id.Equals(e.CustomerId)).FirstOrDefault();
                                    customer.TotalCredit = customer.TotalCredit + e.SMSPrice;
                                }
                            }
                        }
                        cxt.SaveChanges();
                        trans.Commit();
                        NSLog.Logger.Info("Update Status SMS success: " + id + "==" + status);
                    }
                    catch (Exception ex)
                    {
                        msg    = "Vui lòng kiểm tra đường truyền";
                        result = false;
                        NSLog.Logger.Error("Update Status SMS  " + id + " :", ex);
                        trans.Rollback();
                    }
                    finally
                    {
                        cxt.Dispose();
                    }
                }
            }
            return(result);
        }
Пример #13
0
        public bool Delete(string Id, ref string msg)
        {
            NSLog.Logger.Info("NewsDelete", Id);
            var Result = true;

            using (var cxt = new CMS_Context())
            {
                using (var trans = cxt.Database.BeginTransaction())
                {
                    try
                    {
                        var e = cxt.CMS_News.Find(Id);
                        if (e != null)
                        {
                            e.Status = (byte)Commons.EStatus.Deleted;
                            cxt.SaveChanges();
                            trans.Commit();
                        }
                        else
                        {
                            msg = "Vui lòng kiểm tra đường truyền";
                        }
                        NSLog.Logger.Info("ResponseNewsDelete", new { Result, msg });
                    }
                    catch (Exception ex)
                    {
                        Result = false;
                        msg    = "Vui lòng kiểm tra đường truyền";
                        trans.Rollback();
                        NSLog.Logger.Info("ErrorNewsDelete", ex);
                    }
                    finally
                    {
                        cxt.Dispose();
                    }
                }
            }
            return(Result);
        }
Пример #14
0
        public bool Delete(string Id, ref string msg)
        {
            var Result = true;

            using (var cxt = new CMS_Context())
            {
                using (var trans = cxt.Database.BeginTransaction())
                {
                    try
                    {
                        // Delete Image of Product
                        var _eImage = cxt.CMS_Images.Where(x => x.ProductId.Equals(Id));
                        cxt.CMS_Images.RemoveRange(_eImage);

                        var e = cxt.CMS_Products.Find(Id);
                        if (e != null)
                        {
                            cxt.CMS_Products.Remove(e);
                            cxt.SaveChanges();
                            trans.Commit();
                        }
                        else
                        {
                            msg = "Vui lòng kiểm tra đường truyền";
                        }
                    }catch (Exception)
                    {
                        Result = false;
                        msg    = "Vui lòng kiểm tra đường truyền";
                        trans.Rollback();
                    }
                    finally
                    {
                        cxt.Dispose();
                    }
                }
            }
            return(Result);
        }
Пример #15
0
        public bool Delete(string Id, string userID, ref string msg)
        {
            var result = true;

            using (var cxt = new CMS_Context())
            {
                using (var trans = cxt.Database.BeginTransaction())
                {
                    try
                    {
                        var e = cxt.CMS_Customers.Find(Id);
                        if (e != null)
                        {
                            e.UpdatedBy   = userID;
                            e.UpdatedDate = DateTime.Now;
                            e.IsActive    = false;
                            e.Email       = "(DELETED)";
                            e.Phone       = "(PDELETED)";
                            e.Status      = (int)Commons.CustomerStatus.Locked;
                        }
                        cxt.SaveChanges();
                        trans.Commit();
                    }
                    catch (Exception ex)
                    {
                        result = false;
                        msg    = "Không thể xóa thể loại này";
                        trans.Rollback();
                    }
                    finally
                    {
                        cxt.Dispose();
                    }
                }
            }
            return(result);
        }
Пример #16
0
        public bool Delete(string Id, ref string msg)
        {
            var Result = true;

            using (var cxt = new CMS_Context())
            {
                using (var trans = cxt.Database.BeginTransaction())
                {
                    try
                    {
                        var e = cxt.CMS_News.Find(Id);
                        if (e != null)
                        {
                            cxt.CMS_News.Remove(e);
                            cxt.SaveChanges();
                            trans.Commit();
                        }
                        else
                        {
                            msg = "Vui lòng kiểm tra đường truyền";
                        }
                    }
                    catch (Exception)
                    {
                        Result = false;
                        msg    = "Vui lòng kiểm tra đường truyền";
                        trans.Rollback();
                    }
                    finally
                    {
                        cxt.Dispose();
                    }
                }
            }
            return(Result);
        }
        public bool CreateOrUpdatePinOfBoard(List <CMS_PinOfBoardModels> models, string createdBy, string KeyWordID, ref string msg)
        {
            var result = true;

            using (var _db = new CMS_Context())
            {
                using (var _trans = _db.Database.BeginTransaction())
                {
                    m_Semaphore.WaitOne();
                    try
                    {
                        _db.Database.CommandTimeout = 500;
                        models = models.GroupBy(x => x.id).Select(x => x.First()).ToList();
                        models = models.Where(x => !string.IsNullOrEmpty(x.id) && x.id.Length <= 60 && x.type.ToLower().Equals("pin")).ToList();
                        var lstPinID       = models.Select(o => o.id).ToList();
                        var lstPinUpdate   = _db.CMS_Pin.Where(o => lstPinID.Contains(o.ID)).ToList();
                        var lstPinUpdateID = lstPinUpdate.Select(o => o.ID).ToList();
                        var lstPinInsert   = models.Where(o => !lstPinUpdateID.Contains(o.id)).ToList();

                        /* update pin */
                        lstPinUpdate = lstPinUpdate.Where(o => o.Status == (byte)Commons.EStatus.Active).ToList();
                        foreach (var uPin in lstPinUpdate)
                        {
                            var repin_Board = models.Where(o => o.id == uPin.ID).Select(o => new
                            {
                                Repin_count = o.repin_count,
                                BoardID     = o.board != null ? o.board.id : null,
                                BoardName   = o.board != null ? o.board.name : null,
                                BoardUrl    = o.board != null ? o.board.url : null,
                            }).FirstOrDefault();
                            if (repin_Board.Repin_count != uPin.Repin_count)
                            {
                                uPin.Repin_count = repin_Board.Repin_count;
                                uPin.UpdatedBy   = createdBy;
                                uPin.UpdatedDate = DateTime.Now;
                            }
                        }

                        /* insert new pin */
                        var listInsertDB        = new List <CMS_Pin>();
                        var listInsertBoard_Pin = new List <CMS_R_Board_Pin>();
                        foreach (var pin in lstPinInsert)
                        {
                            listInsertDB.Add(new CMS_Pin()
                            {
                                ID          = pin.id,
                                Link        = pin.link,
                                Repin_count = pin.repin_count,
                                ImageUrl    = pin.images.Values.Select(o => o.url).First(),
                                Created_At  = pin.created_at,
                                Domain      = pin.domain,
                                Status      = (byte)Commons.EStatus.Active,
                                CreatedBy   = createdBy,
                                CreatedDate = DateTime.Now,
                                UpdatedBy   = createdBy,
                                UpdatedDate = DateTime.Now,
                                BoardID     = pin.board != null ? pin.board.id : null,
                                BoardName   = pin.board != null ? pin.board.name : null,
                                BoardUrl    = pin.board != null ? pin.board.url : null,
                            });

                            listInsertBoard_Pin.Add(new CMS_R_Board_Pin
                            {
                                ID          = Guid.NewGuid().ToString(),
                                BoardID     = pin.board != null ? pin.board.id : null,
                                PinID       = pin.id,
                                Status      = (byte)Commons.EStatus.Active,
                                CreatedBy   = createdBy,
                                CreatedDate = DateTime.Now,
                                UpdatedBy   = createdBy,
                                UpdatedDate = DateTime.Now,
                            });
                        }
                        if (listInsertDB.Count > 0)
                        {
                            _db.CMS_Pin.AddRange(listInsertDB);
                        }
                        /* TABLE BOARD_PIN */
                        if (listInsertBoard_Pin.Count > 0)
                        {
                            _db.CMS_R_Board_Pin.AddRange(listInsertBoard_Pin);
                        }

                        _db.SaveChanges();
                        _trans.Commit();
                    }
                    catch (Exception ex)
                    {
                        NSLog.Logger.Error("CreateOrUpdatePinOfBoard", ex);
                        result = false;
                        _trans.Rollback();
                    }
                    finally
                    {
                        _db.Dispose();
                        m_Semaphore.Release();
                    }
                }
            }
            return(result);
        }
Пример #18
0
        public bool CreateOrUpdate(CMS_EmployeeModels model, ref string msg)
        {
            var result = true;

            using (var cxt = new CMS_Context())
            {
                using (var trans = cxt.Database.BeginTransaction())
                {
                    try
                    {
                        if (string.IsNullOrEmpty(model.Id))
                        {
                            var _Id = Guid.NewGuid().ToString();
                            var e   = new CMS_Employee
                            {
                                Id               = _Id,
                                BirthDate        = model.BirthDate,
                                CreatedBy        = model.CreatedBy,
                                CreatedDate      = DateTime.Now,
                                Employee_Address = model.Employee_Address,
                                Employee_Email   = model.Employee_Email,
                                Employee_IDCard  = model.Employee_IDCard,
                                Employee_Phone   = model.Employee_Phone,
                                FirstName        = model.FirstName,
                                IsActive         = model.IsActive,
                                LastName         = model.LastName,
                                Password         = model.Password,
                                UpdatedBy        = model.UpdatedBy,
                                UpdatedDate      = DateTime.Now,
                                ImageURL         = model.ImageURL,
                                Level            = model.Level,
                                Position         = model.Position,
                                LinkFB           = model.LinkFB,
                                LinkInstagram    = model.LinkInstagram,
                                LinkPinterest    = model.LinkPinterest,
                                LinkTwiter       = model.LinkTwiter
                            };
                            cxt.CMS_Employees.Add(e);
                        }
                        else
                        {
                            var e = cxt.CMS_Employees.Find(model.Id);
                            if (e != null)
                            {
                                e.BirthDate        = model.BirthDate;
                                e.UpdatedBy        = model.UpdatedBy;
                                e.Employee_Address = model.Employee_Address;
                                e.Employee_Email   = model.Employee_Email;
                                e.Employee_IDCard  = model.Employee_IDCard;
                                e.Employee_Phone   = model.Employee_Phone;
                                e.FirstName        = model.FirstName;
                                e.LastName         = model.LastName;
                                e.IsActive         = model.IsActive;
                                e.Password         = model.Password;
                                e.UpdatedDate      = DateTime.Now;
                                e.ImageURL         = model.ImageURL;
                                e.Position         = model.Position;
                                e.Level            = model.Level;
                                e.LinkTwiter       = model.LinkTwiter;
                                e.LinkPinterest    = model.LinkPinterest;
                                e.LinkInstagram    = model.LinkInstagram;
                                e.LinkFB           = model.LinkFB;
                            }
                        }
                        cxt.SaveChanges();
                        trans.Commit();
                    }
                    catch (Exception ex)
                    {
                        msg    = "Lỗi hệ thống! Vui lòng load lại.";
                        result = false;
                        trans.Rollback();
                    }
                    finally
                    {
                        cxt.Dispose();
                    }
                }
            }
            return(result);
        }
        public bool CreateOrUpdate(CMS_GroupBoardsModels model, ref string msg)
        {
            var result = true;

            using (var _db = new CMS_Context())
            {
                using (var trans = _db.Database.BeginTransaction())
                {
                    m_Semaphore.WaitOne();
                    try
                    {
                        if (string.IsNullOrEmpty(model.Id))
                        {
                            /* check dup old key */
                            model.Name = model.Name.Trim();
                            var checkDup = _db.CMS_GroupBoard.Where(o => o.Name.Trim() == model.Name.Trim()).FirstOrDefault();

                            if (checkDup == null)
                            {
                                /* get current seq */
                                var curSeq = _db.CMS_GroupBoard.OrderByDescending(o => o.Sequence).Select(o => o.Sequence).FirstOrDefault();

                                /* add new record */
                                var newGroup = new CMS_GroupBoard()
                                {
                                    ID          = Guid.NewGuid().ToString(),
                                    Name        = model.Name,
                                    Status      = (byte)Commons.EStatus.Active,
                                    CreatedBy   = model.CreatedBy,
                                    CreatedDate = DateTime.Now,
                                    UpdatedBy   = model.CreatedBy,
                                    UpdatedDate = DateTime.Now,
                                    Sequence    = ++curSeq,
                                };
                                _db.CMS_GroupBoard.Add(newGroup);
                            }
                            else if (checkDup.Status != (byte)Commons.EStatus.Active) /* re-active old key */
                            {
                                checkDup.Status      = (byte)Commons.EStatus.Active;
                                checkDup.UpdatedBy   = model.CreatedBy;
                                checkDup.UpdatedDate = DateTime.Now;
                            }
                            else /* duplicate group */
                            {
                                msg = "Duplicate group.";
                            }

                            _db.SaveChanges();
                            trans.Commit();
                        }
                        else
                        {
                            msg = "Unable to edit group.";
                        }
                    }
                    catch (Exception ex)
                    {
                        msg    = "Check connection, please!";
                        result = false;
                        trans.Rollback();
                    }
                    finally
                    {
                        _db.Dispose();
                        m_Semaphore.Release();
                    }
                }
            }
            return(result);
        }
Пример #20
0
        public bool CreateOrUpdate(CMS_PaymentMethodModels model, ref string msg)
        {
            var result = true;

            using (var cxt = new CMS_Context())
            {
                using (var trans = cxt.Database.BeginTransaction())
                {
                    try
                    {
                        if (string.IsNullOrEmpty(model.Id))
                        {
                            var _Id = Guid.NewGuid().ToString();
                            var e   = new CMS_PaymentMethod
                            {
                                Id                = _Id,
                                PaymentName       = model.PaymentName,
                                PaymentType       = model.PaymentType,
                                WalletMoney       = model.WalletMoney,
                                ReferenceExchange = model.ReferenceExchange,
                                ScaleNumber       = model.ScaleNumber,
                                TagContent        = model.TagContent,
                                IsActive          = model.IsActive,
                                UpdatedBy         = model.UpdatedBy,
                                UpdatedDate       = DateTime.Now,
                                CreatedBy         = model.CreatedBy,
                                CreatedDate       = DateTime.Now,
                                URLApi            = model.URLApi
                            };
                            cxt.CMS_PaymentMethod.Add(e);
                        }
                        else
                        {
                            var e = cxt.CMS_PaymentMethod.Find(model.Id);
                            if (e != null)
                            {
                                e.PaymentName       = model.PaymentName;
                                e.PaymentType       = model.PaymentType;
                                e.WalletMoney       = model.WalletMoney;
                                e.ReferenceExchange = model.ReferenceExchange;
                                e.ScaleNumber       = model.ScaleNumber;
                                e.TagContent        = model.TagContent;
                                e.IsActive          = model.IsActive;
                                e.UpdatedDate       = DateTime.Now;
                                e.UpdatedBy         = model.UpdatedBy;
                                e.URLApi            = model.URLApi;
                            }
                        }
                        cxt.SaveChanges();
                        trans.Commit();
                    }
                    catch (Exception ex)
                    {
                        msg    = "Vui lòng kiểm tra đường truyền";
                        result = false;
                        trans.Rollback();
                    }
                    finally
                    {
                        cxt.Dispose();
                    }
                }
            }
            return(result);
        }
Пример #21
0
        public bool CreateOrUpdate(CMS_ProductsModels model, ref string msg)
        {
            var Result = true;

            using (var cxt = new CMS_Context())
            {
                using (var trans = cxt.Database.BeginTransaction())
                {
                    try
                    {
                        if (string.IsNullOrEmpty(model.Id))
                        {
                            var _Id = Guid.NewGuid().ToString();
                            var e   = new CMS_Products
                            {
                                Id           = _Id,
                                CategoryId   = model.CategoryId,
                                CreatedBy    = model.CreatedBy,
                                CreatedDate  = DateTime.Now,
                                Description  = model.Description,
                                ProductCode  = model.ProductCode,
                                ProductName  = model.ProductName,
                                ProductPrice = model.ProductPrice,
                                UpdatedBy    = model.UpdatedBy,
                                UpdatedDate  = DateTime.Now,
                                IsActive     = model.IsActive
                            };
                            cxt.CMS_Products.Add(e);

                            if (model.ListImages != null && model.ListImages.Any())
                            {
                                var _e = new List <CMS_Images>();
                                model.ListImages.ForEach(x =>
                                {
                                    _e.Add(new CMS_Images
                                    {
                                        Id          = Guid.NewGuid().ToString(),
                                        CreatedBy   = model.CreatedBy,
                                        CreatedDate = DateTime.Now,
                                        ImageURL    = x.ImageURL,
                                        ProductId   = _Id,
                                        UpdatedBy   = model.UpdatedBy,
                                        UpdatedDate = DateTime.Now
                                    });
                                });
                                cxt.CMS_Images.AddRange(_e);
                            }
                        }
                        else
                        {
                            var e = cxt.CMS_Products.Find(model.Id);
                            if (e != null)
                            {
                                e.ProductName  = model.ProductName;
                                e.ProductCode  = model.ProductCode;
                                e.ProductPrice = model.ProductPrice;
                                e.Description  = model.Description;
                                e.CategoryId   = model.CategoryId;
                                e.UpdatedBy    = model.UpdatedBy;
                                e.UpdatedDate  = DateTime.Now;
                                e.IsActive     = model.IsActive;
                            }

                            if (model.ListImages != null && model.ListImages.Any())
                            {
                                var _edel = cxt.CMS_Images.Where(x => x.ProductId.Equals(e.Id));
                                cxt.CMS_Images.RemoveRange(_edel);

                                var _e = new List <CMS_Images>();
                                model.ListImages.ForEach(x =>
                                {
                                    _e.Add(new CMS_Images
                                    {
                                        Id          = Guid.NewGuid().ToString(),
                                        CreatedBy   = model.CreatedBy,
                                        CreatedDate = DateTime.Now,
                                        ImageURL    = x.ImageURL,
                                        ProductId   = e.Id,
                                        UpdatedBy   = model.UpdatedBy,
                                        UpdatedDate = DateTime.Now
                                    });
                                });
                                cxt.CMS_Images.AddRange(_e);
                            }
                        }
                        cxt.SaveChanges();
                        trans.Commit();
                    }
                    catch (Exception ex) {
                        Result = false;
                        msg    = "Vui lòng kiểm tra đường truyền";
                        trans.Rollback();
                    }
                    finally
                    {
                        cxt.Dispose();
                    }
                }
            }
            return(Result);
        }
Пример #22
0
        public bool InsertOrUpdate(CustomerModels model, ref string msg)
        {
            var result = true;

            using (var cxt = new CMS_Context())
            {
                using (var trans = cxt.Database.BeginTransaction())
                {
                    try
                    {
                        if (string.IsNullOrEmpty(model.ID))
                        {
                            var e = new CMS_Customers
                            {
                                Id            = Guid.NewGuid().ToString(),
                                Address       = model.Address,
                                BirthDate     = model.BirthDate,
                                City          = model.City,
                                CompanyName   = model.CompanyName,
                                Country       = model.Country,
                                CreatedBy     = model.CreatedBy,
                                CreatedDate   = DateTime.Now,
                                Description   = model.Description,
                                Email         = model.Email,
                                FirstName     = model.FirstName,
                                Gender        = model.Gender,
                                ImageURL      = model.ImageURL,
                                IsActive      = model.IsActive,
                                LastName      = model.LastName,
                                MaritalStatus = model.MaritalStatus,
                                Password      = model.Password,
                                Phone         = model.Phone,
                                Street        = model.Street,
                                UpdatedBy     = model.UpdatedBy,
                                UpdatedDate   = DateTime.Now
                            };
                            cxt.CMS_Customers.Add(e);
                        }
                        else
                        {
                            var e = cxt.CMS_Customers.Find(model.ID);
                            if (e != null)
                            {
                                e.Address       = model.Address;
                                e.BirthDate     = model.BirthDate;
                                e.City          = model.City;
                                e.CompanyName   = model.CompanyName;
                                e.Country       = model.Country;
                                e.UpdatedBy     = model.UpdatedBy;
                                e.FirstName     = model.FirstName;
                                e.Description   = model.Description;
                                e.Email         = model.Email;
                                e.Gender        = model.Gender;
                                e.ImageURL      = model.ImageURL;
                                e.IsActive      = model.IsActive;
                                e.LastName      = model.LastName;
                                e.MaritalStatus = model.MaritalStatus;
                                e.Password      = model.Password;
                                e.Phone         = model.Phone;
                                e.Street        = model.Street;
                            }
                        }
                        cxt.SaveChanges();
                        trans.Commit();
                    }
                    catch (Exception ex) {
                        result = false;
                        trans.Rollback();
                        msg = "Lỗi đường truyền mạng";
                    }
                    finally
                    {
                        cxt.Dispose();
                    }
                }
            }
            return(result);
        }
Пример #23
0
        public bool CreateOrUpdate(CMS_AccountModels model, ref string msg)
        {
            var result = true;

            using (var cxt = new CMS_Context())
            {
                using (var trans = cxt.Database.BeginTransaction())
                {
                    try
                    {
                        if (string.IsNullOrEmpty(model.Id))
                        {
                            var checkDup = cxt.CMS_Account.Where(o => o.Name == model.Account).FirstOrDefault();

                            if (checkDup == null)
                            {
                                var curSeq = cxt.CMS_Account.OrderByDescending(o => o.Sequence).Select(o => o.Sequence).FirstOrDefault() == null ? 0 : cxt.CMS_Account.OrderByDescending(o => o.Sequence).Select(o => o.Sequence).FirstOrDefault();

                                var dateTimeNow = DateTime.Now;
                                var newAccount  = new CMS_Account()
                                {
                                    Id          = Guid.NewGuid().ToString(),
                                    Name        = model.Account,
                                    Cookies     = model.Cookies,
                                    IsActive    = model.IsActive,
                                    Status      = (byte)Commons.EStatus.Active,
                                    CreatedBy   = model.CreatedBy,
                                    CreatedDate = dateTimeNow,
                                    UpdatedBy   = model.CreatedBy,
                                    UpdatedDate = dateTimeNow,
                                    Sequence    = ++curSeq,
                                };
                                cxt.CMS_Account.Add(newAccount);
                            }
                            else if (checkDup.Status != (byte)Commons.EStatus.Active)
                            {
                                checkDup.Status      = (byte)Commons.EErrorStatus.AccPending;
                                checkDup.UpdatedBy   = model.CreatedBy;
                                checkDup.UpdatedDate = DateTime.Now;
                            }
                            else /* duplicate key word */
                            {
                                msg = "Duplicate account.";
                            }
                            cxt.SaveChanges();
                            trans.Commit();
                        }
                        else
                        {
                            msg = "Unable to edit account.";
                        }
                    }
                    catch (Exception ex)
                    {
                        msg    = "Check connection, please!";
                        result = false;
                        trans.Rollback();
                    }
                    finally
                    {
                        cxt.Dispose();
                    }
                }
            }
            return(result);
        }
Пример #24
0
        public bool CreateOrUpdate(CMS_MarketingModels model, ref string msg)
        {
            var result = true;

            using (var cxt = new CMS_Context())
            {
                using (var trans = cxt.Database.BeginTransaction())
                {
                    try
                    {
                        if (string.IsNullOrEmpty(model.Id))
                        {
                            var _Id = Guid.NewGuid().ToString();
                            var e   = new CMS_Marketing
                            {
                                Id           = _Id,
                                CustomerId   = model.CustomerId,
                                CustomerName = model.CustomerName,
                                OperatorName = model.OperatorName,
                                RunTime      = model.RunTime.Value,
                                SendFrom     = model.SendFrom,
                                SendTo       = model.SendTo,
                                SMSContent   = model.SMSContent,
                                SMSPrice     = model.SMSPrice,
                                SMSType      = model.SMSType,
                                Status       = model.Status,
                                SMSRate      = model.SMSRate,
                                TimeInput    = model.TimeInput,
                                IsActive     = model.IsActive,
                                UpdatedBy    = model.UpdatedBy,
                                UpdatedDate  = DateTime.Now,
                                CreatedBy    = model.CreatedBy,
                                CreatedDate  = DateTime.Now,
                            };
                            cxt.CMS_Marketing.Add(e);
                        }
                        else
                        {
                            var e = cxt.CMS_Marketing.Find(model.Id);
                            if (e != null)
                            {
                                e.CustomerId   = model.CustomerId;
                                e.CustomerName = model.CustomerName;
                                e.OperatorName = model.OperatorName;
                                e.RunTime      = model.RunTime.Value;
                                e.SendFrom     = model.SendFrom;
                                e.SendTo       = model.SendTo;
                                e.SMSContent   = model.SMSContent;
                                e.SMSPrice     = model.SMSPrice;
                                e.SMSType      = model.SMSType;
                                e.Status       = model.Status;
                                e.SMSRate      = model.SMSRate;
                                e.TimeInput    = model.TimeInput;
                                e.IsActive     = model.IsActive;
                                e.UpdatedDate  = DateTime.Now;
                                e.UpdatedBy    = model.UpdatedBy;
                            }
                        }
                        cxt.SaveChanges();
                        trans.Commit();
                    }
                    catch (Exception ex)
                    {
                        msg    = "Vui lòng kiểm tra đường truyền";
                        result = false;
                        trans.Rollback();
                    }
                    finally
                    {
                        cxt.Dispose();
                    }
                }
            }
            return(result);
        }
Пример #25
0
        public bool CreateOrder(CMS_CheckOutModels model, ref string OrderId)
        {
            NSLog.Logger.Info("CreateOrder_Request:", model);
            var ret = true;

            using (var db = new CMS_Context())
            {
                using (var trans = db.Database.BeginTransaction())
                {
                    m_Semaphore.WaitOne();
                    try
                    {
                        var active = (byte)Commons.EStatus.Actived;
                        if (string.IsNullOrEmpty(model.Customer.Id) && !string.IsNullOrEmpty(model.Customer.LastName))
                        {
                            // create new customer
                            model.Customer.Id = Guid.NewGuid().ToString();
                            var eCus = new CMS_Customer
                            {
                                ID            = model.Customer.Id,
                                FirstName     = model.Customer.FirstName,
                                LastName      = model.Customer.LastName,
                                Email         = model.Customer.Email,
                                Phone         = model.Customer.Phone,
                                CreatedDate   = DateTime.Now,
                                LastModified  = DateTime.Now,
                                CustomerType  = (int)CMS_Common.Commons.ECustomerType.Anonymous,
                                HomeCountry   = model.Customer.Country,
                                OfficeZipCode = model.Customer.PostCode,
                                Status        = active,
                                Anniversary   = Commons.MinDate,
                                ValidTo       = Commons.MinDate,
                                HomeStreet    = model.Customer.Address,
                                OfficeStreet  = model.Customer.Address,
                            };
                            db.CMS_Customer.Add(eCus);
                        }
                        // create order
                        OrderId = Guid.NewGuid().ToString();
                        var eOrder = new CMS_Order
                        {
                            ID      = OrderId,
                            StoreID = model.StoreID,
                            //OrderNo = CommonHelper.RandomNumberOrder(),
                            OrderNo            = CommonHelper.GenerateOrderNo(model.StoreID, active, model.OrderType),
                            ReceiptNo          = model.IsTemp ? "" : CommonHelper.GenerateReceiptNo(model.StoreID, active, model.OrderType),
                            ReceiptCreatedDate = model.IsTemp ? Commons.MinDate : DateTime.Now,
                            CustomerID         = model.Customer.Id,
                            TotalBill          = model.TotalPrice,
                            SubTotal           = model.SubTotalPrice,
                            TotalDiscount      = model.TotalDiscount,
                            Cashier            = model.IsTemp ? "" : model.CreatedUser,
                            CreatedDate        = DateTime.Now,
                            LastModified       = DateTime.Now,
                            CreatedUser        = string.IsNullOrEmpty(model.CreatedUser) ? model.Customer.Id : model.CreatedUser,
                            ModifiedUser       = string.IsNullOrEmpty(model.ModifiedUser) ? model.Customer.Id : model.ModifiedUser,
                            Status             = active,
                            IsTemp             = model.IsTemp,
                            OrderType          = model.OrderType,
                        };
                        db.CMS_Order.Add(eOrder);
                        // create order detail
                        if (model.ListItem != null && model.ListItem.Any())
                        {
                            var lstOrderDetail = new List <CMS_OrderDetail>();
                            foreach (var item in model.ListItem)
                            {
                                lstOrderDetail.Add(new CMS_OrderDetail
                                {
                                    ID           = Guid.NewGuid().ToString(),
                                    OrderID      = OrderId,
                                    ProductID    = item.ProductID,
                                    Remark       = string.IsNullOrEmpty(item.ProductID) ? item.ProductName : "",
                                    Price        = item.Price,
                                    Quantity     = (decimal)item.Quantity,
                                    Description  = string.IsNullOrEmpty(model.Customer.Description) ? item.Description : model.Customer.Description,
                                    CreatedDate  = DateTime.Now,
                                    CreatedUser  = string.IsNullOrEmpty(model.CreatedUser) ? model.Customer.Id : model.CreatedUser,
                                    ModifiedUser = string.IsNullOrEmpty(model.ModifiedUser) ? model.Customer.Id : model.ModifiedUser,
                                    //CreatedUser = model.IsTemp ? model.Customer.Id : (string.IsNullOrEmpty(item.EmployeeID) ? model.CreatedUser : item.EmployeeID),
                                    //ModifiedUser = model.IsTemp ? model.Customer.Id : (string.IsNullOrEmpty(item.EmployeeID) ? model.ModifiedUser : item.EmployeeID),
                                    EmployeeID     = item.EmployeeID,
                                    LastModified   = DateTime.Now,
                                    DiscountID     = item.DiscountID,
                                    DiscountValue  = item.DiscountValue,
                                    DiscountType   = item.DiscountType,
                                    DiscountAmount = item.DiscountAmount,
                                    Status         = active,
                                });
                            }
                            db.CMS_OrderDetail.AddRange(lstOrderDetail);

                            /* update quantity of product */
                            var listProductID = model.ListItem.Select(o => o.ProductID).ToList();
                            var listProductDB = db.CMS_Products.Where(o => listProductID.Contains(o.ID) && o.Status == (byte)Commons.EStatus.Actived && o.TypeCode == (byte)Commons.EProductType.Product).ToList();
                            foreach (var product in listProductDB)
                            {
                                var sign = -1;
                                if (model.OrderType == (byte)Commons.EOrderType.Expense)
                                {
                                    sign = +1;
                                }

                                product.Quantity = product.Quantity + ((sign) * (decimal)(model.ListItem.Where(o => o.ProductID == product.ID).Select(o => o.Quantity).FirstOrDefault()));

                                //if (product.Quantity < 0)
                                //{
                                //    ret = false;
                                //}
                            }
                        }

                        if (ret == true)
                        {
                            db.SaveChanges();
                            trans.Commit();
                        }
                    }
                    catch (Exception ex)
                    {
                        NSLog.Logger.Error("CreateOrder_Error:", ex);
                        trans.Rollback();
                        ret = false;
                    }
                    finally
                    {
                        m_Semaphore.Release();
                        db.Dispose();
                    }
                }
            }
            return(ret);
        }
Пример #26
0
        public bool CreateOrUpdate(CMS_DepositPackageModel model, ref string msg)
        {
            var result = true;

            using (var cxt = new CMS_Context())
            {
                using (var trans = cxt.Database.BeginTransaction())
                {
                    try
                    {
                        if (string.IsNullOrEmpty(model.Id))
                        {
                            var _Id = Guid.NewGuid().ToString();
                            var e   = new CMS_DepositPackage
                            {
                                Id          = _Id,
                                PackageName = model.PackageName,
                                PackageSMS  = model.PackageSMS,
                                //PackagePrice = model.PackagePrice,
                                Discount    = model.Discount,
                                SMSPrice    = model.SMSPrice,
                                IsActive    = model.IsActive,
                                UpdatedBy   = model.UpdatedBy,
                                UpdatedDate = DateTime.Now,
                                CreatedBy   = model.CreatedBy,
                                CreatedDate = DateTime.Now,
                            };
                            cxt.CMS_DepositPackage.Add(e);
                        }
                        else
                        {
                            var e = cxt.CMS_DepositPackage.Find(model.Id);
                            if (e != null)
                            {
                                e.PackageName = model.PackageName;
                                e.PackageSMS  = model.PackageSMS;
                                //e.PackagePrice = model.PackagePrice;
                                e.Discount    = model.Discount;
                                e.SMSPrice    = model.SMSPrice;
                                e.IsActive    = model.IsActive;
                                e.UpdatedDate = DateTime.Now;
                                e.UpdatedBy   = model.UpdatedBy;
                            }
                        }
                        cxt.SaveChanges();
                        trans.Commit();
                    }
                    catch (Exception ex)
                    {
                        msg    = "Vui lòng kiểm tra đường truyền";
                        result = false;
                        trans.Rollback();
                    }
                    finally
                    {
                        cxt.Dispose();
                    }
                }
            }
            return(result);
        }
Пример #27
0
        public bool CreateOrUpdate(CMS_CompanyModels model, ref string msg)
        {
            var result = true;

            using (var cxt = new CMS_Context())
            {
                using (var trans = cxt.Database.BeginTransaction())
                {
                    try
                    {
                        if (string.IsNullOrEmpty(model.ID))
                        {
                            var e = new CMS_Companies
                            {
                                Id            = Guid.NewGuid().ToString(),
                                Name          = model.Name,
                                Description   = model.Description,
                                Email         = model.Email,
                                Phone         = model.Phone,
                                Address       = model.Address,
                                LinkBlog      = model.LinkBlog,
                                LinkTwiter    = model.LinkTwiter,
                                LinkInstagram = model.LinkInstagram,
                                LinkFB        = model.LinkFB,
                                ImageURL      = model.ImageURL,
                                IsActive      = true,
                                BusinessHour  = model.Businesshour,
                                CreatedBy     = model.CreatedBy,
                                CreatedDate   = DateTime.Now,
                                UpdatedBy     = model.UpdatedBy,
                                UpdatedDate   = DateTime.Now
                            };
                            cxt.CMS_Companies.Add(e);
                        }
                        else
                        {
                            var e = cxt.CMS_Companies.Find(model.ID);
                            if (e != null)
                            {
                                e.Name          = model.Name;
                                e.Description   = model.Description;
                                e.Email         = model.Email;
                                e.Phone         = model.Phone;
                                e.Address       = model.Address;
                                e.LinkBlog      = model.LinkBlog;
                                e.LinkTwiter    = model.LinkTwiter;
                                e.LinkInstagram = model.LinkInstagram;
                                e.LinkFB        = model.LinkFB;
                                //e.ImageURL = model.ImageURL;
                                e.IsActive     = true;
                                e.BusinessHour = model.Businesshour;
                                e.UpdatedBy    = model.UpdatedBy;
                                e.UpdatedDate  = DateTime.Now;
                            }
                            if (!string.IsNullOrEmpty(model.ImageURL))
                            {
                                e.ImageURL = model.ImageURL;
                            }
                        }
                        cxt.SaveChanges();
                        trans.Commit();
                    }
                    catch (Exception ex)
                    {
                        result = false;
                        trans.Rollback();
                        msg = "Lỗi đường truyền mạng";
                    }
                    finally
                    {
                        cxt.Dispose();
                    }
                }
            }
            return(result);
        }
        public bool CreateOrUpdate(CMS_BoardModels model, ref string msg)
        {
            var result = true;

            using (var _db = new CMS_Context())
            {
                using (var trans = _db.Database.BeginTransaction())
                {
                    m_Semaphore.WaitOne();
                    try
                    {
                        if (string.IsNullOrEmpty(model.id)) /* get board ID */
                        {
                            model.url = GetUrl(model.url);
                            GetBoardInfo(model);
                        }

                        if (!string.IsNullOrEmpty(model.id))
                        {
                            /* check dup old key */
                            var checkDup = _db.CMS_Board.Where(o => o.ID == model.id).FirstOrDefault();

                            if (checkDup == null)
                            {
                                /* get current seq */
                                var curSeq = _db.CMS_Board.OrderByDescending(o => o.Sequence).Select(o => o.Sequence).FirstOrDefault() ?? 0;


                                /* add new record */
                                var dateTimeNow = DateTime.Now;
                                var newKey      = new CMS_Board()
                                {
                                    ID          = model.id,
                                    BoardName   = model.name,
                                    Url         = model.url,
                                    OwnerName   = model.owner != null ? model.owner.username : "",
                                    Pin_count   = model.pin_count,
                                    Description = model.description,
                                    Sequence    = ++curSeq,


                                    Status = (byte)Commons.EStatus.Active,
                                    //CreatedBy = model.CreatedBy,
                                    CreatedDate = dateTimeNow,
                                    //UpdatedBy = model.CreatedBy,
                                    UpdatedDate = dateTimeNow,
                                };
                                _db.CMS_Board.Add(newKey);
                            }
                            else if (checkDup.Status != (byte)Commons.EStatus.Active) /* re-active old key */
                            {
                                checkDup.Status = (byte)Commons.EStatus.Active;
                                //checkDup.UpdatedBy = model.by;
                                checkDup.UpdatedDate = DateTime.Now;
                            }
                            else /* duplicate key word */
                            {
                                result = false;
                                msg    = "Duplicate board, please check your board.";
                            }

                            _db.SaveChanges();
                            trans.Commit();
                        }
                        else
                        {
                            result = false;
                            msg    = "Invalid board, please check your board.";
                        }
                    }
                    catch (Exception ex)
                    {
                        msg    = "Check connection, please!";
                        result = false;
                        trans.Rollback();
                    }
                    finally
                    {
                        _db.Dispose();
                        m_Semaphore.Release();
                    }
                }
            }
            return(result);
        }
Пример #29
0
        public bool Delete(string Id, string Reason = "")
        {
            var result = true;

            using (var db = new CMS_Context())
            {
                using (var trans = db.Database.BeginTransaction())
                {
                    try
                    {
                        var _master = db.CMS_Order.Where(o => o.ID.Equals(Id)).FirstOrDefault();
                        if (_master != null)
                        {
                            _master.Status = (byte)CMS_Common.Commons.EStatus.Deleted;
                            _master.Reason = Reason;
                        }

                        // db.CMS_Order.Remove(_master);

                        var _detail = db.CMS_OrderDetail.Where(o => o.OrderID.Equals(Id)).ToList();
                        if (_detail != null)
                        {
                            foreach (var item in _detail)
                            {
                                item.Status = (byte)CMS_Common.Commons.EStatus.Deleted;
                            }
                        }
                        //db.CMS_OrderDetail.RemoveRange(_detail);

                        /* update quantity of product */
                        var listProductID = _detail.Select(o => o.ProductID).ToList();
                        var listProductDB = db.CMS_Products.Where(o => listProductID.Contains(o.ID) && o.Status == (byte)Commons.EStatus.Actived && o.TypeCode == (byte)Commons.EProductType.Product).ToList();
                        foreach (var product in listProductDB)
                        {
                            var sign = 1;
                            if (_master.OrderType == (byte)Commons.EOrderType.Expense)
                            {
                                sign = -1;
                            }

                            product.Quantity = product.Quantity + ((sign) * (decimal)(_detail.Where(o => o.ProductID == product.ID).Select(o => o.Quantity).FirstOrDefault()));

                            //if (product.Quantity < 0)
                            //{
                            //    result = false;
                            //}
                        }

                        if (result == true)
                        {
                            db.SaveChanges();
                            trans.Commit();
                        }
                    }
                    catch (Exception ex)
                    {
                        result = false;
                        NSLog.Logger.Error("Delete_Order:", ex);
                        trans.Rollback();
                    }
                    finally
                    {
                        db.Dispose();
                    }
                }
            }
            return(result);
        }
Пример #30
0
        public bool CreateOrUpdate(CMS_KeywordModels model, ref string msg)
        {
            var result = true;

            using (var _db = new CMS_Context())
            {
                using (var trans = _db.Database.BeginTransaction())
                {
                    m_Semaphore.WaitOne();
                    try
                    {
                        if (string.IsNullOrEmpty(model.Id))
                        {
                            /* check dup old key */
                            var key  = model.KeySearch;
                            var key2 = "";
                            if (key[key.Length - 1] == '/')
                            {
                                key2 = key.Substring(0, key.Length - 1);
                            }
                            else
                            {
                                key2 = key + "/";
                            }
                            var checkDup = _db.CMS_KeyWord.Where(o => o.KeyWord == key || o.KeyWord == key2).FirstOrDefault();

                            if (checkDup == null)
                            {
                                /* get current seq */
                                var curSeq = _db.CMS_KeyWord.OrderByDescending(o => o.Sequence).Select(o => o.Sequence).FirstOrDefault();

                                /* add new record */
                                var dateTimeNow = DateTime.Now;
                                var newKey      = new CMS_KeyWord()
                                {
                                    ID          = Guid.NewGuid().ToString(),
                                    KeyWord     = model.KeySearch,
                                    Status      = (byte)Commons.EStatus.Active,
                                    CreatedBy   = model.CreatedBy,
                                    CreatedDate = dateTimeNow,
                                    UpdatedBy   = model.CreatedBy,
                                    UpdatedDate = dateTimeNow,
                                    Sequence    = ++curSeq,
                                };
                                _db.CMS_KeyWord.Add(newKey);
                            }
                            else if (checkDup.Status != (byte)Commons.EStatus.Active) /* re-active old key */
                            {
                                checkDup.Status      = (byte)Commons.EStatus.Active;
                                checkDup.UpdatedBy   = model.CreatedBy;
                                checkDup.UpdatedDate = DateTime.Now;
                            }
                            else /* duplicate key word */
                            {
                                result = false;
                                msg    = "Duplicate key word.";
                            }

                            _db.SaveChanges();
                            trans.Commit();
                        }
                        else
                        {
                            result = false;
                            msg    = "Unable to edit key word.";
                        }
                    }
                    catch (Exception ex)
                    {
                        msg    = "Check connection, please!";
                        result = false;
                        trans.Rollback();
                    }
                    finally
                    {
                        _db.Dispose();
                        m_Semaphore.Release();
                    }
                }
            }
            return(result);
        }