public ActionResult Result(ExamModel model) { ExamService objService = new ExamService(); int uid = 0; if (Session["UID"] != null) { uid = Convert.ToInt32(Session["UID"].ToString()); } var lstResult = Dbcontext.ResultMasters.Where(m => m.EID == model.EID && m.StudID == model.StudID && m.SubID == model.SubID).SingleOrDefault(); if (lstResult != null) { ResultMaster res = Dbcontext.ResultMasters.Where(r => r.EID == model.EID && r.StudID == model.StudID && r.SubID == model.SubID).SingleOrDefault(); res.Marks = model.Marks; res.UpdatedBy = uid; res.UpdatedDate = System.DateTime.Now; Dbcontext.SaveChanges(); } else { model.CreatedBy = uid; model.CreatedDate = System.DateTime.Now; objService.InsertResult(model); } return(RedirectToAction("Result")); }
/// <summary> /// Create Assign Holiday /// </summary> /// <param name="createHoliday"></param> /// <returns></returns> public bool CreateAssignHoliday(CreateHolidayViewModel createHoliday, out string msg) { msg = ""; try { Resource_Holiday resourceHoliday = new Resource_Holiday(); resourceHoliday.ResourceID = createHoliday.ResourceID; resourceHoliday.HolidayTypeID = createHoliday.HolidayTypeID; resourceHoliday.BookingHrs = createHoliday.BookingHrs; resourceHoliday.HolidayDate = createHoliday.HolidayStartDate; resourceHoliday.Comments = createHoliday.Comment; _db.Resource_Holiday.Add(resourceHoliday); // _db.SaveChanges(); Resource_HolidayStatus resourceHolidayStatus = new Resource_HolidayStatus(); resourceHolidayStatus.HolidayID = resourceHoliday.HolidayID; resourceHolidayStatus.StatusChangedBy = HttpContext.Current.User.Identity.Name; resourceHolidayStatus.StatusDateTime = createHoliday.RequestedOn.Add(DateTime.Now.TimeOfDay); resourceHolidayStatus.HolidayStatusTypeID = createHoliday.StatusID == 0? _db.Resource_HolidayStatusType.Where(x => x.HolidayStatusType == "Request").Select(x => x.HolidayStatusTypeID).FirstOrDefault(): createHoliday.StatusID; //resourceHolidayStatus.Comments = createHoliday.Comment; _db.Resource_HolidayStatus.Add(resourceHolidayStatus); _db.SaveChanges(); msg = "Successfully Created"; return(true); } catch (Exception ex) { msg = ex.Message; return(false); } }
/// <summary> /// Save Branch Details to DB /// </summary> /// <param name="branchInfoBO"></param> /// <param name="eMessage"></param> /// <returns></returns> public bool SaveBranchDetails(BranchInfoBO branchInfoBO, out string eMessage) { eMessage = ""; var existingTypeBranchCode = db.Branch_Details.Where(t => t.BranchCode == branchInfoBO.BranchCode).SingleOrDefault(); var existingTypeBranchName = db.Branch_Details.Where(t => t.BranchName == branchInfoBO.BranchName).SingleOrDefault(); try { if (existingTypeBranchCode != null) { eMessage = "Branch Code Is Already Exist...!!"; return(false); } if (existingTypeBranchName != null) { eMessage = "Branch Name Is Already Exist..!!"; return(false); } if (branchInfoBO.Address.CountryID != 1) { eMessage = "PAF Is Only Used For UK, So please Select a Country As a UK..!! "; return(false); } var branchdetails = new Branch_Details(); //branchdetails.AddressID = (int)branchInfoBO.AddressID; branchdetails.BranchCode = branchInfoBO.BranchCode; branchdetails.BranchName = branchInfoBO.BranchName; branchdetails.BranchTypeID = (int)branchInfoBO.BranchTypeID; branchdetails.BranchStatusID = (int)branchInfoBO.BranchStatusID; branchdetails.Fax = branchInfoBO.FaxNumber; branchdetails.Telephone = branchInfoBO.TelephoneNumber; branchdetails.VATNumber = branchInfoBO.VATnumber; branchdetails.Status = false; db.Branch_Details.Add(branchdetails); if (branchInfoBO.Address.Postcode != null) { branchdetails.AddressID = (int)addressBL.CheckAddress(branchInfoBO.Address); branchInfoBO.AddressID = branchInfoBO.Address.AddressID = branchdetails.AddressID; if (branchInfoBO.Address.AddressID == 0) { eMessage = "AddressId Is Not Saved "; return(false); } } db.SaveChanges(); eMessage = "Successfully Saved "; return(true); } catch (Exception e) { eMessage = e.Message; return(false); } }
public int Post <T>(IList <T> data) where T : ERPData { var dataset = context.Set <T>(); dataset.AddRange(data); // return number of updated objects to db return(context.SaveChanges()); }
public ActionResult ChangePwd(FormCollection All) { int uid = 0; string opwd = All["txtOpwd"]; string email = All["txtEmail"]; string npwd = All["txtNpwd"]; string ncpwd = All["txtNCpwd"]; if (Session["UID"] != null) { uid = Convert.ToInt32(Session["UID"].ToString()); } var lst = Dbcontext.UserMasters.Where(m => m.UID == uid).SingleOrDefault(); if (lst.Password == opwd && lst.Email == email) { if (npwd == ncpwd) { UserMaster um = Dbcontext.UserMasters.Where(m => m.UID == uid).SingleOrDefault(); um.Password = ncpwd; Dbcontext.SaveChanges(); ////TempData["AMsg"] = "Password changed successfully."; TempData["AMsg"] = "Password changed successfully."; Response.Redirect("/Login/Index"); return(Content("<script language='javascript' type='text/javascript'>alert('Password changed successfully.');</script>")); } else { //TempData["AMsg"] = "Status Not Updated"; //return Content("<script language='javascript' type='text/javascript'>alert('New Password and Confirm New Password Not Matched.');</script>"); TempData["AMsg"] = "New Password and Confirm New Password Not Matched."; return(RedirectToAction("Index")); } } else if (lst.Password != opwd) { //return Content("<script language='javascript' type='text/javascript'>alert('Old Password Not Matched.');</script>"); TempData["AMsg"] = "Old Password Not Matched."; return(RedirectToAction("Index")); } else if (lst.Email != email) { //return Content("<script language='javascript' type='text/javascript'>alert('Email Not Matched.');</script>"); TempData["AMsg"] = "Email Not Matched."; return(RedirectToAction("Index")); } else { //return Content("<script language='javascript' type='text/javascript'>alert('Error occured, Try again!!!');</script>"); TempData["AMsg"] = "Error occured, Try again!!!"; return(RedirectToAction("Index")); } }
//private UserPermissionView userPermissionView = new UserPermissionView(); /// <summary> /// Create User Permission Details /// </summary> /// <param name="userPermissionView"></param> public void CreateUserPermission(UserRoleViewModel userRoleViewModel) { foreach (var item in userRoleViewModel.SelectPermissions) { var per = (from auth in db.AspNetPermissions where (auth.PermissionID == item) select auth).FirstOrDefault(); var rol = (from role in db.AspNetRoles where (role.Name == userRoleViewModel.RoleName) select role).FirstOrDefault(); rol.AspNetPermissions.Add(per); } db.SaveChanges(); }
public ActionResult Create(DictionaryType model) { // if (ModelState.IsValid) { db.DictionaryTypes.Add(model); //添加 db.SaveChanges(); //提交至数据库 return(RedirectToAction("Index")); } return(View(model)); }
//public List<SchoolModel> getPComp() //{ // try // { // Mapper.CreateMap<SchoolMaster, SchoolModel>(); // List<SchoolMaster> objCityMaster = Dbcontext.SchoolMasters.Where(m => m.Status == true && m.PCompID == null).ToList(); // List<SchoolModel> objCityItem = Mapper.Map<List<SchoolModel>>(objCityMaster); // return objCityItem; // } // catch (Exception ex) // { // throw ex; // } //} public int Insert(SchoolModel model) { try { Mapper.CreateMap <SchoolModel, SchoolMaster>(); SchoolMaster objUser = Mapper.Map <SchoolMaster>(model); Dbcontext.SchoolMasters.Add(objUser); return(Dbcontext.SaveChanges()); } catch (Exception ex) { throw ex; } }
public ActionResult Create(SubMenu subMenu) { if (subMenu != null) { subMenu.CreatedBy = System.Web.HttpContext.Current.User.Identity.Name; subMenu.CreatedDate = DateTime.Now; subMenu.IsActive = true; db.SubMenus.Add(subMenu); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(subMenu)); }
public int InsertComp(CompanyModel model) { try { Mapper.CreateMap <CompanyModel, CompanyMaster>(); CompanyMaster objUser = Mapper.Map <CompanyMaster>(model); Dbcontext.CompanyMasters.Add(objUser); return(Dbcontext.SaveChanges()); } catch (Exception ex) { throw ex; } }
public ActionResult AddCountry(country country) { if (country.id > 0) { db.Entry(country).State = EntityState.Modified; } else { var newId = db.countries.Max(x => x.id + 1); country.id = newId; db.countries.Add(country); } db.SaveChanges(); return(RedirectToAction("CountryList")); }
public ActionResult Create(Menu menu) { if (menu != null) { menu.CreatedBy = System.Web.HttpContext.Current.User.Identity.Name; menu.CreatedDate = DateTime.Now; menu.IsActive = menu.IsActive; db.Menus.Add(menu); db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.CompanyId = new SelectList(db.Companies, "CompanyId", "Name", menu.CompanyId); return(View(menu)); }
public ActionResult Create(UserMenu userMenu) { if (ModelState.IsValid) { userMenu.CreatedBy = System.Web.HttpContext.Current.User.Identity.Name; userMenu.CreatedDate = DateTime.Now; userMenu.IsActive = true; db.UserMenus.Add(userMenu); db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.MenuId = new SelectList(db.Menus, "MenuId", "Name", userMenu.MenuId); ViewBag.SubMenuId = new SelectList(db.SubMenus, "SubMenuId", "Name", userMenu.SubMenuId); return(View(userMenu)); }
public void Delete(T entity) { using (ERPEntities entities = new ERPEntities()) { try { entities.Entry(entity).State = EntityState.Deleted; entities.SaveChanges(); } catch (DbEntityValidationException e) { Exception raise = e; foreach (var eve in e.EntityValidationErrors) { foreach (var ve in eve.ValidationErrors) { string message = string.Format("{0}:{1}", eve.Entry.Entity.ToString(), ve.ErrorMessage); raise = new InvalidOperationException(message, raise); } } throw raise; } } }
public bool SaveYearlyHoliday(int id, YearlyHolidayModel model) { if (model == null) { throw new Exception("Holiday data missing"); } YearlyHoliday yearlyHoliday = ObjectConverter <YearlyHolidayModel, YearlyHoliday> .Convert(model); if (id > 0) { yearlyHoliday = yearlyHolidayRepository.YearlyHolidays.FirstOrDefault(x => x.YearlyHolidayId == id); if (yearlyHoliday == null) { throw new Exception("Holiday Data not found!"); } //yearlyHoliday.ModifiedDate = DateTime.Now; //yearlyHoliday.ModifedBy = ""; //employeeRepository.Entry(employee).State = System.Data.Entity.EntityState.Modified; } else { yearlyHoliday.CreatedBy = System.Web.HttpContext.Current.User.Identity.Name; yearlyHoliday.CreatedDate = DateTime.Now; } yearlyHoliday.HolidayDate = model.HolidayDate; yearlyHoliday.HolidayCategory = model.HolidayCategory; yearlyHoliday.Purpose = model.Purpose; yearlyHolidayRepository.Entry(yearlyHoliday).State = yearlyHoliday.YearlyHolidayId == 0 ? EntityState.Added : EntityState.Modified; return(yearlyHolidayRepository.SaveChanges() > 0); }
public bool SaveAdminSetUp(long id, AdminSetUpModel model) { if (model == null) { throw new Exception("Admin SetUp data missing!"); } AdminSetUp adminSetUp = ObjectConverter <AdminSetUpModel, AdminSetUp> .Convert(model); if (id > 0) { adminSetUp = adminSetUpRepository.AdminSetUps.FirstOrDefault(x => x.AdminId == id); if (adminSetUp == null) { throw new Exception("Admin SetUp not found!"); } adminSetUp.ModifiedBy = System.Web.HttpContext.Current.User.Identity.Name; adminSetUp.ModifiedDate = DateTime.Now; } else { adminSetUp.CreatededBy = System.Web.HttpContext.Current.User.Identity.Name; adminSetUp.CreatedDate = DateTime.Now; } adminSetUp.Id = model.Id; adminSetUp.IsActive = model.IsActive; adminSetUpRepository.Entry(adminSetUp).State = adminSetUp.AdminId == 0 ? EntityState.Added : EntityState.Modified; return(adminSetUpRepository.SaveChanges() > 0); }
public int Insert(StudentModel model) { try { Mapper.CreateMap <StudentModel, StudentMaster>(); StudentMaster objUser = Mapper.Map <StudentMaster>(model); Dbcontext.StudentMasters.Add(objUser); Dbcontext.SaveChanges(); int id = Dbcontext.StudentMasters.Max(m => m.StudID); return(id); } catch (Exception ex) { throw ex; } }
public ActionResult ResetPwd(FormCollection All) { string email = All["txtEmail"]; var lst = Dbcontext.UserMasters.Where(m => m.Email == email).SingleOrDefault(); int uid = 0; if (lst != null) { uid = lst.UID; UserMaster um = Dbcontext.UserMasters.Where(m => m.UID == uid).SingleOrDefault(); um.UserName = lst.Email; um.Password = Convert.ToString(lst.Mobile); Dbcontext.SaveChanges(); TempData["AMsg"] = "Password has been reset, you can login with email as username and mobile as password"; //TempData["UserMsg"] = "Password has been reset, you can login with email as username and mobile as password"; Response.Redirect("/Login/Index"); return(Content("<script language='javascript' type='text/javascript'>alert('Password has been reset, you can login with email as username and mobile as password');</script>")); } else { TempData["AMsg"] = "Email Not Matched!"; //return Content("<script language='javascript' type='text/javascript'>alert('New Password and Confirm New Password Not Matched.');</script>"); //TempData["EMsg"] = "Email Not Matched."; Response.Redirect("/Login/Index"); return(Content("<script language='javascript' type='text/javascript'>alert('Email Not Matched.');</script>")); } }
public void Delete(T entity) { using (ERPEntities entities = new ERPEntities()) { entities.Entry(entity).State = EntityState.Deleted; entities.SaveChanges(); } }
public int Insert(UserModel model) { try { Mapper.CreateMap <UserModel, UserMaster>(); UserMaster objUser = Mapper.Map <UserMaster>(model); Dbcontext.UserMasters.Add(objUser); Dbcontext.SaveChanges(); int uid = Dbcontext.UserMasters.Max(m => m.UID); return(uid); } catch (Exception ex) { throw ex; } }
public ActionResult DeleteConfirmed(int id) { Customer kttlCustomer = db.Customers.Find(id); db.Customers.Remove(kttlCustomer); db.SaveChanges(); return(RedirectToAction("Index")); }
public void Insert(T entity) { using (ERPEntities entities = new ERPEntities()) { entities.Set <T>().Add(entity); entities.SaveChanges(); } }
public void Update(T entity) { using (ERPEntities entities = new ERPEntities()) { entities.Entry(entity).State = EntityState.Modified; entities.SaveChanges(); } }
public ActionResult Create([Bind(Include = "Name,Code,IsActive")] DropDownType dropDownType) { if (ModelState.IsValid) { if (!string.IsNullOrEmpty(Session["UserName"].ToString())) { dropDownType.CreatedBy = Session["UserName"].ToString(); dropDownType.CreatedDate = DateTime.Now; dropDownType.ModifiedBy = Session["UserName"].ToString(); dropDownType.ModifiedDate = DateTime.Now; } db.DropDownTypes.Add(dropDownType); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(dropDownType)); }
public bool SaveKttlCustomer(long id, CustomerModel model) { bool result = false; try { Customer customer = ObjectConverter <CustomerModel, Customer> .Convert(model); if (id > 0) { customer.ModifiedDate = DateTime.Now; customer.ModifiedBy = System.Web.HttpContext.Current.User.Identity.Name; } else { customer.CreatedBy = System.Web.HttpContext.Current.User.Identity.Name; customer.CreatedDate = DateTime.Now; } customer.CustomerId = model.CustomerId; customer.CustomerType = model.CustomerType; customer.CustomerName = model.CustomerName; customer.AddressOne = model.AddressOne; //customer.FiscalYear = model.FiscalYear; customer.Telephone = model.Telephone; customer.MobileNo = model.MobileNo; customer.TIN = model.TIN; customer.ContactPersonName = model.ContactPersonName; customer.ConcatPersonEmail = model.ConcatPersonEmail; customer.AddressTwo = model.AddressTwo; customer.DateOfBirth = model.DateOfBirth; customer.Nationality = model.Nationality; customer.Email = model.Email; customer.Designation = model.Designation; customer.Division = model.Division; customer.District = model.District; //customer.LogoUrl = model.LogoUrl; //customer.ImageUrl = model.ImageUrl; customer.Remarks = model.Remarks; context.Entry(customer).State = customer.OID == 0 ? EntityState.Added : EntityState.Modified; result = context.SaveChanges() > 0; } catch (DbEntityValidationException ex) { foreach (DbEntityValidationResult errors in ex.EntityValidationErrors) { foreach (DbValidationError validationError in errors.ValidationErrors) { // get the error message string errorMessage = validationError.ErrorMessage; result = false; } } } return(result); }
private AddressBL addressBL = new AddressBL(); //Gets all the methods from "AddressBL" /// <summary> /// Save the User Details /// </summary> /// <param name="userViewModel"></param> public bool CreateUser(UserViewModel userViewModel, out string msg) { try { if (userViewModel.AddressViewModel.Postcode != null) { userViewModel.AddressID = (int)addressBL.CheckAddress(userViewModel.AddressViewModel); //Assign a AddressID for Employee userViewModel.AddressViewModel.AddressID = userViewModel.AddressID; if (userViewModel.AddressViewModel.AddressID == 0) { msg = "AddressID Is Not Saved!....."; return(false); } } userViewModel.DOB = new DateTime(userViewModel.Year, userViewModel.Month, userViewModel.Day); User_UserDetails users = new User_UserDetails(); users.UserId = userViewModel.UserID; users.TitleID = (int)userViewModel.TitleID; users.FirstName = userViewModel.FirstName; users.LastName = userViewModel.LastName; users.UserName = userViewModel.Username; users.Telephone = userViewModel.Telephone; users.Mobile = userViewModel.Mobile; users.DateofBirth = userViewModel.DOB; users.EmployeeNo = userViewModel.EmployeeNO; users.JoinDate = userViewModel.JoinDate; users.Email = userViewModel.Email; users.Status = userViewModel.Status; users.StatusComment = userViewModel.StatusComment; users.AddressID = userViewModel.AddressID; users.JobTitleID = (short)userViewModel.JobTitleID; db.User_UserDetails.Add(users); db.SaveChanges(); msg = "Successfully Created!"; } catch (Exception ex) { msg = ex.Message; return(false); } return(true); }
public ActionResult Create([Bind(Include = "DropDownTypeId,Name,Value,Description")] DropDownItem dropDownItem) { if (ModelState.IsValid) { if (!string.IsNullOrEmpty(Session["UserName"].ToString())) { dropDownItem.CreatedBy = Convert.ToInt64(Session["Id"].ToString()); dropDownItem.CreatedDate = DateTime.Now; dropDownItem.ModifiedBy = Convert.ToInt64(Session["Id"].ToString()); dropDownItem.ModifiedDate = DateTime.Now; } db.DropDownItems.Add(dropDownItem); db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.DropDownTypeId = new SelectList(db.DropDownTypes, "DropDownTypeId", "Name", dropDownItem.DropDownTypeId); return(View(dropDownItem)); }
public ActionResult Registration([Bind(Exclude = "IsEmailVerified,ActivationCode")] UserModel model) { bool Status = false; string message = ""; User user = ObjectConverter <UserModel, User> .Convert(model); if (ModelState.IsValid) { #region //Email is already Exist var isExist = IsEmailExist(user.Email); if (isExist) { ModelState.AddModelError("EmailExist", "Email already exist"); return(View(user)); } #endregion #region Generate Activation Code user.ActivationCode = Guid.NewGuid(); #endregion #region Password Hashing user.Password = Crypto.Hash(user.Password); // user.ConfirmPassword = Crypto.Hash(user.ConfirmPassword); #endregion user.IsEmailVerified = true; #region Save to Database using (ERPEntities dc = new ERPEntities()) { dc.Users.Add(user); dc.SaveChanges(); //Send Email to User //SendVerificationLinkEmail(user.EmailID, user.ActivationCode.ToString()); //message = "Registration successfully done. Account activation link " + // " has been sent to your email id:" + user.EmailID; Status = true; } #endregion } else { message = "Invalid Request"; } ViewBag.Message = message; ViewBag.Status = Status; return(View(user)); }
public void Setup() { ERPEntities context = new ERPEntities(); // delete all books in DB var books = context.Set <Book>(); context.Books.RemoveRange(books); // delete all deals in DB var deals = context.Set <Deal>(); context.Deals.RemoveRange(deals); context.SaveChanges(); }
public ActionResult ChangePasswordTemporary() { using (ERPEntities context = new ERPEntities()) { // var users = context.Users.ToList(); var employeeId = "KG1088"; string password = "******"; User user = context.Users.FirstOrDefault(x => x.UserName == employeeId); if (user != null) { user.Password = Crypto.Hash(password); context.SaveChanges(); } return(View()); } }