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); }
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 List <CMS_NewsModels> GetList() { try { using (var cxt = new CMS_Context()) { var data = cxt.CMS_News .Select(x => new CMS_NewsModels { Id = x.Id, Title = x.Title, Short_Description = x.Short_Description, ImageURL = x.ImageURL, CreatedBy = x.CreatedBy, CreatedDate = x.CreatedDate, Description = x.Description, IsActive = x.IsActive, UpdatedBy = x.UpdatedBy, UpdatedDate = x.UpdatedDate, }).ToList(); return(data); } } catch (Exception) { } return(null); }
public CMS_ReservationViewModels GetDetail(string Id) { NSLog.Logger.Info("CateReservationDetail", Id); CMS_ReservationViewModels result = null; try { using (var cxt = new CMS_Context()) { var data = cxt.CMS_Reservation.Where(o => o.ID == Id && o.Status != (byte)Commons.EStatus.Deleted) .Join(cxt.CMS_ReservationDetail, r => r.ID, d => d.ReservationID, (r, d) => new { r, d }) .Select(o => new CMS_ReservationViewModels { Id = o.r.ID, CustomerName = o.r.CustomerName, Phone = o.r.Mobile, BookDay = o.r.Date, //FromTime = o.r.Date-o.r.Date.Date, Remark = o.r.Remark, ProductID = o.d.ProductID, ProductName = o.d.ProductName, }).FirstOrDefault(); data.FromTime = data.BookDay - data.BookDay.Date; result = data; NSLog.Logger.Info("ResponseReservationGetDetail", result); } } catch (Exception ex) { NSLog.Logger.Error("ErrorReservationGetDetail", ex); } return(result); }
public CMS_ProductsModels GetDetail(string Id) { try { using (var cxt = new CMS_Context()) { var e = cxt.CMS_Products.Join(cxt.CMS_Categories, p => p.CategoryId, c => c.Id, (p, c) => new { p, CategoryName = c.CategoryName }) .Where(x => x.p.Id.Equals(Id)).FirstOrDefault(); if (e != null) { var o = new CMS_ProductsModels { Id = e.p.Id, CategoryId = e.p.CategoryId, CreatedBy = e.p.CreatedBy, CreatedDate = e.p.CreatedDate, Description = e.p.Description, IsActive = e.p.IsActive, ProductCode = e.p.ProductCode, ProductName = e.p.ProductName, ProductPrice = e.p.ProductPrice, UpdatedBy = e.p.UpdatedBy, UpdatedDate = e.p.UpdatedDate, CategoryName = e.CategoryName }; return(o); } } } catch (Exception ex) { } return(null); }
public List <CMS_DepositPackageModel> GetList() { try { using (var cxt = new CMS_Context()) { decimal smsRate = GetSMSRate(cxt); decimal usdRate = GetUSDRate(cxt); decimal pmRate = GetPMRate(cxt); var data = cxt.CMS_DepositPackage.Select(x => new CMS_DepositPackageModel { Id = x.Id, PackageName = x.PackageName, PackageSMS = x.PackageSMS, PackagePrice = x.PackageSMS * smsRate, RateSMS = smsRate, Discount = x.Discount, SMSPrice = x.SMSPrice, IsActive = x.IsActive, UpdatedBy = x.UpdatedBy, UpdatedDate = x.UpdatedDate, CreatedBy = x.CreatedBy, CreatedDate = x.CreatedDate, PriceUSD = usdRate != 0 ? (x.Discount != 0 ? ((x.PackageSMS * smsRate) - (x.PackageSMS * smsRate * x.Discount / 100)) / usdRate : (x.PackageSMS * smsRate) / usdRate) : 0, //PriceDefault = pmRate == 0 ? 0 : usdRate/ pmRate, PriceDefault = usdRate != 0 ? (x.Discount != 0 ? ((x.PackageSMS * smsRate) - (x.PackageSMS * smsRate * x.Discount / 100)) / usdRate : (x.PackageSMS * smsRate) / usdRate) : 0, }).OrderBy(o => o.PackageSMS).ToList(); return(data); } } catch (Exception ex) { } return(null); }
public CMS_MarketingModels GetDetail(string Id) { try { using (var cxt = new CMS_Context()) { var data = cxt.CMS_Marketing.Where(x => x.Id.Equals(Id)) .Select(x => new CMS_MarketingModels { Id = x.Id, CustomerId = x.CustomerId, CustomerName = x.CustomerName, OperatorName = x.OperatorName, RunTime = x.RunTime, SendFrom = x.SendFrom, SendTo = x.SendTo, SMSContent = x.SMSContent, SMSPrice = x.SMSPrice, SMSType = x.SMSType, IsActive = x.IsActive, Status = x.Status, TimeInput = x.TimeInput, UpdatedBy = x.UpdatedBy, UpdatedDate = x.UpdatedDate, CreatedBy = x.CreatedBy, CreatedDate = x.CreatedDate, }).FirstOrDefault(); return(data); } } catch (Exception) { } return(null); }
public CMS_CompanyModels GetInfor() { try { using (var cxt = new CMS_Context()) { var data = cxt.CMS_Companies.Select(x => new CMS_CompanyModels { ID = x.Id, Name = x.Name, Description = x.Description, Email = x.Email, Phone = x.Phone, Address = x.Address, LinkBlog = x.LinkBlog, LinkTwiter = x.LinkTwiter, LinkInstagram = x.LinkInstagram, LinkFB = x.LinkFB, ImageURL = string.IsNullOrEmpty(x.ImageURL) ? "" : Commons.HostImage + x.ImageURL, IsActive = true, CreatedBy = x.CreatedBy, CreatedDate = DateTime.Now, UpdatedBy = x.UpdatedBy, UpdatedDate = DateTime.Now }).FirstOrDefault(); return(data); } } catch (Exception ex) { } return(null); }
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); }
public List <CMS_EmployeeModels> GetList() { try { using (var cxt = new CMS_Context()) { var data = cxt.CMS_Employees.Select(x => new CMS_EmployeeModels { Id = x.Id, BirthDate = x.BirthDate, CreatedBy = x.CreatedBy, CreatedDate = x.CreatedDate, Employee_Address = x.Employee_Address, Employee_Email = x.Employee_Email, Employee_IDCard = x.Employee_IDCard, Employee_Phone = x.Employee_Phone, FirstName = x.FirstName, IsActive = x.IsActive, LastName = x.LastName, Password = x.Password, UpdatedBy = x.UpdatedBy, UpdatedDate = x.UpdatedDate, ImageURL = x.ImageURL, IsSupperAdmin = x.IsSupperAdmin, }).ToList(); return(data); } } catch (Exception) { } return(null); }
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); }
public CMS_EmployeeModels GetDetail(string Id) { try { using (var cxt = new CMS_Context()) { var data = cxt.CMS_Employees.Where(x => x.Id.Equals(Id)) .Select(x => new CMS_EmployeeModels { Id = x.Id, BirthDate = x.BirthDate, CreatedBy = x.CreatedBy, CreatedDate = x.CreatedDate, Employee_Address = x.Employee_Address, Employee_Email = x.Employee_Email, Employee_IDCard = x.Employee_IDCard, Employee_Phone = x.Employee_Phone, FirstName = x.FirstName, IsActive = x.IsActive, LastName = x.LastName, Password = x.Password, UpdatedBy = x.UpdatedBy, UpdatedDate = x.UpdatedDate, ImageURL = x.ImageURL, IsSupperAdmin = x.IsSupperAdmin, }).FirstOrDefault(); return(data); } } catch (Exception) { } return(null); }
public List <CMS_PermissionModels> GetListModule() { NSLog.Logger.Info("RoleGetListModule"); List <CMS_PermissionModels> result = null; try { using (var cxt = new CMS_Context()) { /* get list module */ result = cxt.CMS_Module.OrderBy(o => o.Code) .Select(o => new CMS_PermissionModels() { ModuleID = o.ID, ModuleName = o.Name, ModuleCode = o.Code, }).ToList(); NSLog.Logger.Info("ResponseRoleGetListModule", result); } } catch (Exception ex) { NSLog.Logger.Error("ErrorRoleGetListModule", ex); } return(result); }
public List <CMS_RoleModels> GetList() { NSLog.Logger.Info("RoleGetList"); List <CMS_RoleModels> result = null; try { using (var cxt = new CMS_Context()) { var data = cxt.CMS_Role.Where(o => o.Status != (byte)Commons.EStatus.Deleted) .Select(o => new CMS_RoleModels { Id = o.ID, StoreID = o.StoreID, Name = o.Name, IsActive = o.IsActive ?? false, }).ToList(); /* response data */ result = data; NSLog.Logger.Info("ResponseRoleGetList", result); } } catch (Exception ex) { NSLog.Logger.Error("ErrorRoleGetList", ex); } return(result); }
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 static string RandomCustomerNo() { string no = string.Empty; try { using (var _db = new CMS_Context()) { int startNo = 1; string prefix = "ID"; int nextNum = startNo; int currentNum = 0; string currentCustomerNo = _db.CMS_Customers.Where(o => !string.IsNullOrEmpty(o.MemberID)).OrderByDescending(o => o.MemberID).Select(o => o.MemberID).FirstOrDefault(); if (!string.IsNullOrEmpty(currentCustomerNo)) { currentCustomerNo = currentCustomerNo.Replace(prefix, ""); currentNum = int.Parse(currentCustomerNo); if (currentNum >= startNo) { nextNum = currentNum + 1; } } no = prefix + nextNum.ToString("000"); } } catch { } return(no); }
public CMS_DepositPackageModel GetDetail(string Id) { try { using (var cxt = new CMS_Context()) { decimal smsRate = GetSMSRate(cxt); decimal usdRate = GetUSDRate(cxt); var data = cxt.CMS_DepositPackage.Where(x => x.Id.Equals(Id)) .Select(x => new CMS_DepositPackageModel { Id = x.Id, PackageName = x.PackageName, PackageSMS = x.PackageSMS, PackagePrice = x.PackageSMS * smsRate, RateSMS = smsRate, RateUSD = usdRate, Discount = x.Discount, SMSPrice = x.SMSPrice, IsActive = x.IsActive, UpdatedBy = x.UpdatedBy, UpdatedDate = x.UpdatedDate, CreatedBy = x.CreatedBy, CreatedDate = x.CreatedDate, }).FirstOrDefault(); return(data); } } catch (Exception) { } return(null); }
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 List <CMS_MarketingModels> GetList(int smsType) { try { using (var cxt = new CMS_Context()) { var data = cxt.CMS_Marketing.Where(x => x.SMSType.Equals(smsType)).Select(x => new CMS_MarketingModels { Id = x.Id, CustomerId = x.CustomerId, CustomerName = x.CustomerName, OperatorName = x.OperatorName, RunTime = x.RunTime, SendFrom = x.SendFrom, SendTo = x.SendTo, SMSContent = x.SMSContent, SMSPrice = x.SMSPrice, SMSType = x.SMSType, IsActive = x.IsActive, Status = x.Status, TimeInput = x.TimeInput, UpdatedBy = x.UpdatedBy, UpdatedDate = x.UpdatedDate, CreatedBy = x.CreatedBy, CreatedDate = x.CreatedDate, }).ToList(); return(data); } } catch (Exception ex) { } return(null); }
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); }
public decimal GetSMSRate(int smsType) { using (var cxt = new CMS_Context()) { return(GetSMSRate(cxt, smsType)); } }
public List <CMS_GalleryModels> getList() { try { using (var _db = new CMS_Context()) { var data = _db.CMS_Products.Join(_db.CMS_ImagesLink, p => p.ID, i => i.ProductId, (p, i) => new { ProductName = p.Name, Status = p.Status, i }) .Where(o => !string.IsNullOrEmpty(o.i.ImageURL) && o.Status == (byte)Commons.EStatus.Actived) .Select(o => new CMS_GalleryModels { ImageUrl = Commons._PublicImages + "Products/" + o.i.ImageURL, ProductName = o.ProductName }).ToList(); NSLog.Logger.Info("getList Gallery Response :", JsonConvert.SerializeObject(data)); return(data); } } catch (Exception ex) { NSLog.Logger.Error("getList Gallery", ex); } return(null); }
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 CMSCategoriesModels GetDetail(string Id) { try { using (var cxt = new CMS_Context()) { var data = cxt.CMS_Categories.Select(x => new CMSCategoriesModels { CategoryCode = x.CategoryCode, CategoryName = x.CategoryName, CreatedBy = x.CreatedBy, CreatedDate = x.CreatedDate, Description = x.Description, Id = x.Id, IsActive = x.IsActive, UpdatedBy = x.UpdatedBy, UpdatedDate = x.UpdatedDate, ParentId = x.ParentId, ImageURL = x.ImageURL, }).Where(x => x.Id.Equals(Id)).FirstOrDefault(); return(data); } } catch (Exception ex) { } return(null); }
public List <CMS_ProductsModels> GetList() { try { using (var cxt = new CMS_Context()) { var data = cxt.CMS_Products.Join(cxt.CMS_Categories, p => p.CategoryId, c => c.Id, (p, c) => new { p, CategoryName = c.CategoryName }) .Select(x => new CMS_ProductsModels { Id = x.p.Id, CategoryId = x.p.CategoryId, CreatedBy = x.p.CreatedBy, CreatedDate = x.p.CreatedDate, Description = x.p.Description, IsActive = x.p.IsActive, ProductCode = x.p.ProductCode, ProductName = x.p.ProductName, ProductPrice = x.p.ProductPrice, UpdatedBy = x.p.UpdatedBy, UpdatedDate = x.p.UpdatedDate, CategoryName = x.CategoryName }).ToList(); return(data); } } catch (Exception) { } return(null); }
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); }
public CMS_NewsModels GetDetail(string Id) { try { using (var cxt = new CMS_Context()) { var e = cxt.CMS_News.Where(x => x.Id.Equals(Id)).FirstOrDefault(); if (e != null) { var o = new CMS_NewsModels { Id = e.Id, CreatedBy = e.CreatedBy, CreatedDate = e.CreatedDate, Description = e.Description, IsActive = e.IsActive, UpdatedBy = e.UpdatedBy, UpdatedDate = e.UpdatedDate, Title = e.Title, Short_Description = e.Short_Description, ImageURL = e.ImageURL }; return(o); } } } catch (Exception ex) { } return(null); }
public LoginResponseModel Login(LoginRequestModel info) { NSLog.Logger.Info("Employee Login Start", info); LoginResponseModel user = null; try { using (CMS_Context _db = new CMS_Context()) { info.Password = CommonHelper.Encrypt(info.Password); string serverImage = ConfigurationManager.AppSettings["PublicImages"]; var emp = _db.CMS_Employee.Where(o => o.Employee_Email == info.Email.ToLower().Trim() && o.Password == info.Password).FirstOrDefault(); if (emp != null) { user = new LoginResponseModel() { EmployeeID = emp.Id, EmployeeName = emp.FirstName + " " + emp.LastName, EmployeeEmail = emp.Employee_Email, EmployeeImageURL = string.IsNullOrEmpty(emp.ImageURL) ? "" : serverImage + "Employees/" + emp.ImageURL, IsSupperAdmin = emp.IsSupperAdmin, }; } NSLog.Logger.Info("Employee Login Done", user); } } catch (Exception ex) { NSLog.Logger.Error("Employee Login Error", ex); } return(user); }
public List <CMS_CategoryViewModels> GetListProductCate() { NSLog.Logger.Info("GetListProductCate"); var result = new List <CMS_CategoryViewModels>(); try { using (var cxt = new CMS_Context()) { var data = cxt.CMS_Categories.GroupJoin(cxt.CMS_Products, c => c.ID, p => p.CategoryID, (c, p) => new { c, p }) .Where(o => o.c.Status != (byte)Commons.EStatus.Deleted /*&& o.c.ProductTypeCode == (int)Commons.EProductType.Product*/) .OrderBy(o => o.c.Sequence) .Select(o => new CMS_CategoryViewModels { Id = o.c.ID, Name = o.c.Name, ParentId = o.c.ParentID, TotalProduct = o.c.CMS_Products.Count }).ToList(); result = data; NSLog.Logger.Info("ResponseGetListProductCate", result); } } catch (Exception ex) { NSLog.Logger.Error("ErrorGetListProductCate", ex); } return(result); }
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); }