public bool UpdateSiteMaintain(CMS_SysConfigModels model, ref string msg)
        {
            var result = true;

            using (var cxt = new CMS_Context())
            {
                using (var beginTran = cxt.Database.BeginTransaction())
                {
                    try
                    {
                        if (!string.IsNullOrEmpty(model.Id))
                        {
                            var e = cxt.CMS_SysConfigs.Find(model.Id);
                            if (e != null)
                            {
                                e.SiteContent = model.SiteContent;
                            }
                        }
                        cxt.SaveChanges();
                        beginTran.Commit();
                    }
                    catch (Exception ex)
                    {
                        msg = "Lỗi đường truyền mạng";
                        beginTran.Rollback();
                        result = false;
                    }
                }
            }
            return(result);
        }
Beispiel #2
0
        public bool DeleteImage(string Id, ref string msg)
        {
            NSLog.Logger.Info("ProductDeleteImage", Id);

            var result = true;

            try
            {
                using (var cxt = new CMS_Context())
                {
                    var e = cxt.CMS_ImagesLink.Find(Id);
                    if (e != null)
                    {
                        msg = e.ImageURL;
                        cxt.CMS_ImagesLink.Remove(e);
                        cxt.SaveChanges();
                    }
                    else
                    {
                        result = false;
                        msg    = "Vui lòng kiểm tra đường truyền";
                    }

                    NSLog.Logger.Info("ResponseProductDeleteImage", new { result, msg });
                }
            }
            catch (Exception ex)
            {
                result = false;
                msg    = "Vui lòng kiểm tra đường truyền";
                NSLog.Logger.Error("ErrorProductDeleteImage", ex);
            }
            return(result);
        }
        public bool ChangeStatusDepositTransaction(List <CMS_DepositTransactionsModel> model, int Status)
        {
            var result = true;

            try
            {
                using (var cxt = new CMS_Context())
                {
                    var Ids = model.Select(x => x.Id).ToList();
                    var e   = cxt.CMS_DepositTransactions.Where(x => Ids.Contains(x.Id)).ToList();
                    e.ForEach(x =>
                    {
                        x.Status      = Status;
                        x.UpdatedDate = DateTime.Now;
                    });

                    cxt.SaveChanges();
                }
            }
            catch (Exception ex)
            {
                NSLog.Logger.Error("ChangeStatusDepositTransaction", ex);
            }
            return(result);
        }
Beispiel #4
0
        public bool ChangeStatus(string ID, ref string msg)
        {
            var result = true;

            try
            {
                using (var cxt = new CMS_Context())
                {
                    var e = cxt.CMS_Account.Find(ID);
                    if (e != null)
                    {
                        //if (!e.IsActive)
                        //{
                        //    var active = cxt.CMS_Account.Where(o=> o.IsActive).FirstOrDefault();
                        //    if (active != null)
                        //    {
                        //        active.IsActive = false;
                        //    }
                        //    e.IsActive = !e.IsActive;
                        //}

                        e.IsActive = !e.IsActive;
                    }

                    cxt.SaveChanges();
                }
            }
            catch (Exception ex)
            {
                msg    = "Can't update status this account.";
                result = false;
            }
            return(result);
        }
        public bool DeleteImage(string Id, ref string msg)
        {
            var result = true;

            try
            {
                using (var cxt = new CMS_Context())
                {
                    var e = cxt.CMS_Images.Find(Id);
                    if (e != null)
                    {
                        msg = e.ImageURL;
                        cxt.CMS_Images.Remove(e);
                        cxt.SaveChanges();
                    }
                    else
                    {
                        result = false;
                        msg    = "Vui lòng kiểm tra đường truyền";
                    }
                }
            }
            catch (Exception ex)
            {
                result = false;
                msg    = "Vui lòng kiểm tra đường truyền";
            }
            return(result);
        }
        public bool ForgotPassword(string email, string newPassword, ref string msg)
        {
            var result = true;

            try
            {
                using (var cxt = new CMS_Context())
                {
                    var Cus = cxt.CMS_Customers.FirstOrDefault(x => x.Email == email && x.IsActive && x.IsActive);
                    if (Cus != null)
                    {
                        Cus.Password    = newPassword;
                        Cus.UpdatedDate = DateTime.Now;
                        cxt.SaveChanges();
                    }
                    else
                    {
                        msg    = "E-mail dose not exits";
                        result = false;
                    }
                }
            } catch (Exception ex)
            {
                NSLog.Logger.Error("ForgotPassword", ex);
                result = false;
            }
            return(result);
        }
Beispiel #7
0
        public bool Delete(string Id, string createdBy, ref string msg)
        {
            var result = true;

            try
            {
                using (var _db = new CMS_Context())
                {
                    var key = _db.CMS_KeyWord.Where(o => o.ID == Id).FirstOrDefault();

                    key.Status      = (byte)Commons.EStatus.Deleted;
                    key.UpdatedDate = DateTime.Now;
                    key.UpdatedBy   = createdBy;

                    /* delete group key */
                    var listGroupKey = _db.CMS_R_GroupKey_KeyWord.Where(o => o.KeyWordID == Id).ToList();
                    listGroupKey.ForEach(o =>
                    {
                        o.Status      = (byte)Commons.EStatus.Deleted;
                        o.UpdatedDate = DateTime.Now;
                        o.UpdatedBy   = createdBy;
                    });

                    _db.SaveChanges();
                }
            }
            catch (Exception ex)
            {
                msg    = "Can't delete this key words.";
                result = false;
            }
            return(result);
        }
        public bool ChangePassword(CustomerChangePasswordModel model, ref string msg)
        {
            var result = true;

            try
            {
                using (var cxt = new CMS_Context())
                {
                    var Cus = cxt.CMS_Customers.FirstOrDefault(x => x.Email == model.Email && x.IsActive && (x.Password == model.LastPassword || x.Password2 == model.LastPassword));
                    if (Cus != null)
                    {
                        Cus.Password    = model.Password;
                        Cus.Password2   = model.Password2;
                        Cus.UpdatedDate = DateTime.Now;
                        cxt.SaveChanges();
                    }
                    else
                    {
                        msg    = "Last password incorrect";
                        result = false;
                    }
                }
            } catch (Exception ex)
            {
                NSLog.Logger.Error("ChangePassword", ex);
                msg    = "Last password incorrect";
                result = false;
            }
            return(result);
        }
        public bool Delete(string Id, ref string msg)
        {
            NSLog.Logger.Info("ReservationDelete", Id);

            var result = true;

            try
            {
                using (var cxt = new CMS_Context())
                {
                    var e = cxt.CMS_Reservation.Find(Id);
                    if (e != null)
                    {
                        e.Status = (byte)Commons.EStatus.Deleted;
                        cxt.SaveChanges();
                    }
                    else
                    {
                        msg    = "Unable to find Reservation.";
                        result = false;
                    }

                    NSLog.Logger.Info("ResponseReservationDelete", new { result, msg });
                }
            }
            catch (Exception ex)
            {
                msg    = "Không thể xóa thể loại này";
                result = false;
                NSLog.Logger.Error("ErrorReservationDelete", ex);
            }
            return(result);
        }
        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);
        }
Beispiel #11
0
        public static void WriteLogs(string description, string jsonContent)
        {
            try
            {
                using (var _db = new CMS_Context())
                {
                    description = description.Length > 98 ? description.Substring(0, 95) + "\n..." : description;
                    jsonContent = jsonContent.Length > 3999 ? jsonContent.Substring(0, 3995) + "\n..." : jsonContent;

                    var logData = new CMS_Log()
                    {
                        ID          = Guid.NewGuid().ToString(),
                        Decription  = description,
                        CreatedDate = DateTime.UtcNow.AddHours(7),
                        JsonContent = jsonContent,
                    };
                    _db.CMS_Log.Add(logData);
                    _db.SaveChanges();

                    _db.Database.CommandTimeout = 500;

                    /* delete log from 7 day ago */
                    _db.Database.ExecuteSqlCommand(
                        "delete CMS_Log where  CreatedDate < DATEADD(DAY,-7,getdate())"
                        );
                }
            }
            catch (Exception ex)
            {
            }
        }
        public bool Delete(string Id, ref string msg)
        {
            NSLog.Logger.Info("CustomersDelete", Id);

            var result = true;

            try
            {
                using (var cxt = new CMS_Context())
                {
                    var e = cxt.CMS_Customer.Find(Id);
                    if (e != null)
                    {
                        e.Status = (byte)Commons.EStatus.Deleted;
                        cxt.SaveChanges();
                    }
                    else
                    {
                        msg    = "Unable to find data to delete.";
                        result = false;
                    }

                    NSLog.Logger.Info("ResponseCustomersDelete", new { result, msg });
                }
            }
            catch (Exception ex)
            {
                msg    = "System Error.";
                result = false;
                NSLog.Logger.Error("ErrorCustomersDelete", ex);
            }
            return(result);
        }
Beispiel #13
0
        public bool ChangAccDefault(string ID, ref string msg)
        {
            var result = true;

            try
            {
                using (var cxt = new CMS_Context())
                {
                    var e = cxt.CMS_Account.Find(ID);
                    if (e != null)
                    {
                        var isDefault = cxt.CMS_Account.Where(o => o.IsDefault).FirstOrDefault();
                        if (isDefault != null)
                        {
                            isDefault.IsDefault = false;
                        }
                        e.IsDefault = !e.IsDefault;
                    }

                    cxt.SaveChanges();
                }
            }
            catch (Exception ex)
            {
                msg    = "Can't update this default account.";
                result = false;
            }
            return(result);
        }
Beispiel #14
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);
        }
Beispiel #15
0
        public bool CheckOut(string OrderId, string createdUser)
        {
            var result = true;

            try
            {
                NSLog.Logger.Info("CheckOut_Request:", OrderId);
                using (var db = new CMS_Context())
                {
                    var Order = db.CMS_Order.Find(OrderId);
                    if (Order != null)
                    {
                        Order.ReceiptNo          = CommonHelper.GenerateReceiptNo(Order.StoreID, (byte)Commons.EStatus.Actived, (byte)Commons.EOrderType.Normal);
                        Order.LastModified       = DateTime.Now;
                        Order.ModifiedUser       = createdUser;
                        Order.Cashier            = createdUser;
                        Order.ReceiptCreatedDate = DateTime.Now;
                        db.SaveChanges();
                    }
                }
            }
            catch (Exception ex)
            {
                result = false;
                NSLog.Logger.Error("CheckOut_Order:", ex);
            }
            return(result);
        }
Beispiel #16
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);
        }
Beispiel #17
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);
        }
Beispiel #18
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);
        }
Beispiel #19
0
        public bool CreateOrUpdate(CMS_APIModels model, ref string Id, ref string msg)
        {
            var result = true;

            using (var cxt = new CMS_Context())
            {
                using (var beginTran = cxt.Database.BeginTransaction())
                {
                    try
                    {
                        if (string.IsNullOrEmpty(model.Id))
                        {
                            var _Id = Guid.NewGuid().ToString();
                            var e   = new CMS_API()
                            {
                                APIName     = model.APIName,
                                LinkAPI     = model.LinkAPI,
                                APIType     = model.APIType,
                                Description = model.Description,
                                CreatedBy   = model.CreatedBy,
                                CreatedDate = DateTime.Now,
                                IsActive    = model.IsActive,
                                UpdatedBy   = model.UpdatedBy,
                                UpdatedDate = DateTime.Now,
                                Id          = _Id
                            };
                            Id = _Id;
                            cxt.CMS_API.Add(e);
                        }
                        else
                        {
                            var e = cxt.CMS_API.Find(model.Id);
                            if (e != null)
                            {
                                e.APIName     = model.APIName;
                                e.LinkAPI     = model.LinkAPI;
                                e.APIType     = model.APIType;
                                e.Description = model.Description;
                                e.IsActive    = model.IsActive;
                                e.UpdatedBy   = model.UpdatedBy;
                                e.UpdatedDate = DateTime.Now;
                            }
                        }
                        cxt.SaveChanges();
                        beginTran.Commit();
                    }
                    catch (Exception ex)
                    {
                        msg = "Lỗi đường truyền mạng";
                        beginTran.Rollback();
                        result = false;
                    }
                }
            }
            return(result);
        }
Beispiel #20
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);
        }
        public bool ForgotPassword(string email, ref string msg)
        {
            NSLog.Logger.Info("CustomerForgotPassword", email);

            var result = false;

            try
            {
                using (var cxt = new CMS_Context())
                {
                    var emp = cxt.CMS_Customer.Where(o => o.Email.ToLower().Trim() == email.ToLower().Trim() && o.Status == (byte)Commons.EStatus.Actived).FirstOrDefault();
                    if (emp != null)
                    {
                        if (emp.IsActive ?? true)
                        {
                            string newPass = CommonHelper.GenerateCode(1, new List <string>(), 8).FirstOrDefault();

                            CommonHelper.SendContentMail(email, "New password: "******"", "[Lamode Beauté Home Spa] Forgot password");

                            emp.Password     = CommonHelper.Encrypt(newPass);
                            emp.LastModified = DateTime.Now;

                            if (cxt.SaveChanges() > 0)
                            {
                                result = true;
                            }
                            else
                            {
                                msg = "Unable to change password.";
                            }
                        }
                        else
                        {
                            msg = "This customer is inactive. Please contact your administrator for more support.";
                        }
                    }
                    else
                    {
                        msg = "Email is not exist.";
                    }

                    NSLog.Logger.Info("ResponseCustomerForgotPassword", new { result, msg });
                }
            }
            catch (Exception ex)
            {
                msg    = "System Error.";
                result = false;
                NSLog.Logger.Error("ErrorCustomerForgotPassword", ex);
            }
            return(result);
        }
Beispiel #22
0
        public bool DeleteAndRemoveDB(string Id, ref string msg)
        {
            var result = true;

            try
            {
                using (var _db = new CMS_Context())
                {
                    _db.Database.CommandTimeout = 500;

                    /* remove list group key*/
                    var listGroupKey = _db.CMS_R_GroupKey_KeyWord.Where(o => o.KeyWordID == Id).ToList();

                    /* remove list Key pin */
                    var listKeyPin = _db.CMS_R_KeyWord_Pin.Where(o => o.KeyWordID == Id).ToList();

                    _db.CMS_R_GroupKey_KeyWord.RemoveRange(listGroupKey);
                    _db.CMS_R_KeyWord_Pin.RemoveRange(listKeyPin);
                    _db.SaveChanges();

                    /* remove list pin */
                    var listPinID = _db.CMS_R_KeyWord_Pin.Select(o => o.PinID).ToList();
                    var listPin   = _db.CMS_Pin.Where(o => !listPinID.Contains(o.ID)).ToList();

                    /* remove key */
                    var key = _db.CMS_KeyWord.Where(o => o.ID == Id).FirstOrDefault();

                    _db.CMS_Pin.RemoveRange(listPin);
                    _db.CMS_KeyWord.Remove(key);
                    _db.SaveChanges();
                }
            }
            catch (Exception ex)
            {
                msg    = "Can't delete this key words.";
                result = false;
            }
            return(result);
        }
Beispiel #23
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);
        }
Beispiel #24
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 CreateDepositTransaction(List <CMS_DepositTransactionsModel> model, ref string msg, List <string> lstID = null)
        {
            var result = true;

            try
            {
                using (var cxt = new CMS_Context())
                {
                    var es = new List <CMS_DepositTransactions>();
                    foreach (var item in model)
                    {
                        var e = new CMS_DepositTransactions
                        {
                            Id                = Guid.NewGuid().ToString(),
                            CreatedDate       = DateTime.Now,
                            CustomerId        = item.CustomerId,
                            CustomerName      = item.CustomerName,
                            ExchangeRate      = item.ExchangeRate,
                            CreatedBy         = item.CustomerId,
                            IsActive          = true,
                            PackageId         = item.PackageId,
                            PackageName       = item.PackageName,
                            PackagePrice      = item.PackagePrice,
                            PackageSMS        = item.PackageSMS,
                            PayCoin           = item.PayCoin,
                            PaymentMethodId   = item.PaymentMethodId,
                            PaymentMethodName = item.PaymentMethodName,
                            SMSPrice          = item.SMSPrice,
                            UpdatedDate       = DateTime.Now,
                            WalletMoney       = item.WalletMoney,
                            Status            = (int)Commons.DepositStatus.WaitingPay,
                            DepositNo         = item.DepositNo
                        };
                        es.Add(e);
                    }
                    cxt.CMS_DepositTransactions.AddRange(es);
                    cxt.SaveChanges();
                    msg = "Create deposite order successful";
                }
            }
            catch (Exception ex)
            {
                result = false;
                msg    = "Create deposite order not successful";
                NSLog.Logger.Error("CreateDepositTransaction", ex);
            }
            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);
        }
Beispiel #27
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);
        }
        public bool Delete(string Id, ref string msg)
        {
            NSLog.Logger.Info("CateDelete", Id);

            var result = true;

            try
            {
                using (var cxt = new CMS_Context())
                {
                    var e = cxt.CMS_Categories.Find(Id);
                    if (e != null)
                    {
                        var isExistProduct = cxt.CMS_Products.Where(o => o.CategoryID == Id && o.Status != (byte)Commons.EStatus.Deleted).Count() > 0;
                        if (!isExistProduct)
                        {
                            e.Status = (byte)Commons.EStatus.Deleted;
                            cxt.SaveChanges();
                        }
                        else
                        {
                            result = false;
                            msg    = "Have product in this cate, unable to delete cate.";
                        }
                    }
                    else
                    {
                        msg    = "Unable to find cate.";
                        result = false;
                    }

                    NSLog.Logger.Info("ResponseCateDelete", new { result, msg });
                }
            }
            catch (Exception ex)
            {
                msg    = "Không thể xóa thể loại này";
                result = false;
                NSLog.Logger.Error("ErrorCateDelete", ex);
            }
            return(result);
        }
Beispiel #29
0
        public bool Delete(string Id, ref string msg)
        {
            var result = true;

            try
            {
                using (var cxt = new CMS_Context())
                {
                    var e = cxt.CMS_Account.Find(Id);
                    cxt.CMS_Account.Remove(e);
                    cxt.SaveChanges();
                }
            }
            catch (Exception ex)
            {
                msg    = "Can't delete this account.";
                result = false;
            }
            return(result);
        }
Beispiel #30
0
        public bool Delete(string Id, ref string msg)
        {
            var result = true;

            try
            {
                using (var cxt = new CMS_Context())
                {
                    var e = cxt.CMS_Employees.Find(Id);
                    cxt.CMS_Employees.Remove(e);
                    cxt.SaveChanges();
                }
            }
            catch (Exception ex)
            {
                msg    = "Không thể xóa nhân viên này";
                result = false;
            }
            return(result);
        }