public static CustomerViewModel SendEmail(string Custoemrid, string CategoryId, string TemplateId) { bool IsSend = false; string ErrorCode = "", ErrorMessage = ""; CustomerViewModel model = new CustomerViewModel(); try { int UserId = Helper.SessionHelper.GetCurrentUserID(); int intCategoryId = Convert.ToInt32(CategoryId); int intTemplateId = Convert.ToInt32(TemplateId); string[] CustomerIdList = Custoemrid.Split(','); if (CustomerIdList.Length > 0) { for (int i = 0; i <= CustomerIdList.Length - 1; i++) { using (SampleCodeEntities db = new SampleCodeEntities()) { if (CustomerIdList[i].Length > 0) { int CustomerId = Convert.ToInt32(CustomerIdList[i]); var userresult = db.UserRegistrations.FirstOrDefault(x => x.UserId == UserId); string TemplateURL = ""; string Attachment = "~/Template/Portfolio.pdf"; var result = db.Customers.FirstOrDefault(x => x.Id == CustomerId); if (result != null) { string Emailaddress = result.Emailaddress; string CustomerName = result.FirstName + " " + result.LastName; SendEmailTemplate(Emailaddress, result.FirstName, result.LastName, result.CompanyName, userresult.InitialName, userresult.FirstName, userresult.LastName, TemplateURL, Attachment, ref IsSend, ref ErrorCode, ref ErrorMessage); if (IsSend == true) { //Action when email send } } } if (IsSend == false) { model.ErrorCode = ErrorCode; model.ErrorMessage = ErrorMessage; } else { model.ErrorCode = ErrorCode; model.ErrorMessage = ErrorMessage; } } } } return(model); } catch (Exception ex) { ex.Message.ToString(); return(null); } }
public static CategoryViewModel DeleteCategory(int id) { CategoryViewModel model = new CategoryViewModel(); try { using (SampleCodeEntities db = new SampleCodeEntities()) { Category CT = db.Categories.Where(x => x.Id == id).FirstOrDefault(); db.Categories.Remove(CT); if (db.SaveChanges() > 0) { model.ErrorCode = "success"; model.ErrorMessage = "Category deleted successfully."; } else { model.ErrorCode = "Error"; model.ErrorMessage = "Error"; } } } catch (Exception ex) { ex.Message.ToString(); } return(model); }
//Get Category list public static CategoryViewModel GetCategoryList() { CategoryViewModel model = new CategoryViewModel(); model.objModel = new CategoryModel(); try { using (SampleCodeEntities db = new SampleCodeEntities()) { //Bind model.objCategoryListModels = db.Categories.Select(x => new CategoryModel { Name = x.Name, Type = "Type", TypeId = x.TypeId, Rownumber = 0, Id = x.Id } ).ToList(); return(model); } } catch (Exception ex) { ex.Message.ToString(); return(null); } }
public static DashboardViewModel GetDashboardList(int Id) { DashboardViewModel model = new DashboardViewModel(); model.objModel = new DashboardModel(); int UserId = Helper.SessionHelper.GetCurrentUserID(); try { using (SampleCodeEntities db = new SampleCodeEntities()) { model.DashboardListModels = db.usp_s_Dashboard_List(UserId, Id).OrderBy(z => z.OrderNo).Select(x => new DashboardModel { Name = x.Name, Emailaddress = x.Emailaddress, Country = x.Country, ContactNo = x.ContactNo, TypeName = x.TypeName, SendEmail = x.SendEmail, TypeCount = x.TypeCount, BackgroundColor = x.BackgroundColor, ForeColor = x.ForeColor } ).ToList(); return(model); } } catch (Exception ex) { ex.Message.ToString(); return(null); } }
private static bool IsCheckExistsCategory(string Name, string Type) { try { using (SampleCodeEntities db = new SampleCodeEntities()) { return(db.Categories.Any(x => x.Name.ToUpper() == Name.ToUpper())); } } catch (Exception ex) { ex.Message.ToString(); return(false); } }
public static CustomerViewModel ImportCustomer(string FilePath) { CustomerViewModel model = new CustomerViewModel(); DataTable dt = new DataTable(); dt = ProcessCSV(FilePath); using (SampleCodeEntities db = new SampleCodeEntities()) { var parameter = new SqlParameter("@ImportCustomerType", SqlDbType.Structured); parameter.TypeName = "dbo.BulkImportCustomerType"; parameter.Value = dt; db.Database.ExecuteSqlCommand("exec dbo.SP_ImportCustomer @ImportCustomerType", parameter); } return(model); }
public static CustomerViewModel GetCustomerList() { CustomerViewModel model = new CustomerViewModel(); model.objModel = new CustomerModel(); int?UserId = 1; try { using (SampleCodeEntities db = new SampleCodeEntities()) { model.objCustomerListModels = db.Customers.Where(x => UserId == UserId).Select(x => new CustomerModel { FirstName = x.FirstName, LastName = x.LastName, Emailaddress = x.Emailaddress, CompanyName = x.CompanyName, Country = x.Country, ContactNo = x.ContactNo, ResendMsg = "", CustomerId = x.Id, URL = x.URL, ContactPerson = x.ContactPerson, Designation = x.Designation } ).ToList(); model.objCategoryList = db.Categories.Select(y => new CategoryModel { Id = y.Id, Name = y.Name }).ToList(); return(model); } } catch (Exception ex) { ex.Message.ToString(); return(null); } }
public static LoginModel Login(LoginModel loginModel) { try { using (SampleCodeEntities db = new SampleCodeEntities()) { var ePassword = CommonHelper.Encrypt_Password_MD5(loginModel.Password); var dp = CommonHelper.Decrypt_Password_MD5(loginModel.Password); var result = db.UserRegistrations.FirstOrDefault(x => x.Status == "Active" && x.EmailAddress == loginModel.EmailAddress && x.Password == ePassword); if (result != null) { loginModel.UserType = result.UserType.Trim(); if (loginModel.UserType == "ADMIN") { loginModel.UserName = result.EmailAddress; loginModel.UserId = result.UserId; loginModel.userSession = new UserSession(); loginModel.userSession.UserName = result.EmailAddress; loginModel.userSession.UserID = result.UserId; loginModel.userSession.UserType = result.UserType.Trim(); loginModel.ErrorCode = "Success"; loginModel.ErrorMessage = "logged in successfully"; } else { loginModel.ErrorCode = "Error"; loginModel.ErrorMessage = "Login failed username or password is incorrect."; } } } } catch (Exception ex) { ex.Message.ToString(); loginModel.ErrorCode = "Error"; loginModel.ErrorMessage = ex.Message; } return(loginModel); }
public static CustomerViewModel GetCategoryList() { CustomerViewModel model = new CustomerViewModel(); try { using (SampleCodeEntities db = new SampleCodeEntities()) { model.objCategoryList = db.Categories.Select(y => new CategoryModel { Id = y.Id, Name = y.Name }).ToList(); return(model); } } catch (Exception ex) { ex.Message.ToString(); return(null); } }
public ActionResult Edit(int Id) { CustomerViewModel model = new CustomerViewModel(); using (SampleCodeEntities db = new SampleCodeEntities()) { model.objModel = db.Customers.Where(z => z.Id == Id).Select(x => new CustomerModel { FirstName = x.FirstName, LastName = x.LastName, Emailaddress = x.Emailaddress, CompanyName = x.CompanyName, Country = x.Country, ContactNo = x.ContactNo, CustomerId = x.Id, URL = x.URL, ContactPerson = x.ContactPerson, Designation = x.Designation }).FirstOrDefault(); } return(PartialView("_EditCustomer", model)); }
public static CategoryViewModel AddCategory(CategoryViewModel model) { try { using (SampleCodeEntities db = new SampleCodeEntities()) { if (!IsCheckExistsCategory(model.objModel.Name, model.objModel.Type)) { Category C = new Category { Name = model.objModel.Name, TypeId = model.objModel.TypeId }; db.Categories.Add(C); if (db.SaveChanges() > 0) { model.ErrorCode = "Success"; model.ErrorMessage = "Category created successfully."; } else { model.ErrorCode = "Error"; model.ErrorMessage = "Name and Type already Exists!"; } } } } catch (Exception ex) { ex.Message.ToString(); model.ErrorCode = "Error"; model.ErrorMessage = ex.Message; } return(model); }
public ActionResult Update(CustomerViewModel model) { // CustomerViewModel model = new CustomerViewModel(); using (SampleCodeEntities db = new SampleCodeEntities()) { var custinfo = db.Customers.Where(x => x.Id == model.objModel.CustomerId).FirstOrDefault(); custinfo.FirstName = model.objModel.FirstName; custinfo.LastName = model.objModel.LastName; custinfo.Emailaddress = model.objModel.Emailaddress; custinfo.CompanyName = model.objModel.CompanyName; custinfo.Country = model.objModel.Country; custinfo.ContactNo = model.objModel.ContactNo; custinfo.URL = model.objModel.URL; custinfo.ContactPerson = model.objModel.ContactPerson; custinfo.Designation = model.objModel.Designation; if (db.SaveChanges() > 0) { return(RedirectToAction("CustomerList")); } } return(View(model)); }