public ActionResult DeleteStoreAddress(long id) { var gVal = new GenericValidator(); try { if (id < 1) { gVal.Code = -1; gVal.Error = message_Feedback.Invalid_Selection; return(Json(gVal, JsonRequestBehavior.AllowGet)); } var k = new StoreAddressServices().DeleteStoreAddress(id); if (k) { gVal.Code = 5; gVal.Error = message_Feedback.Delete_Success; return(Json(gVal, JsonRequestBehavior.AllowGet)); } gVal.Code = -1; gVal.Error = message_Feedback.Delete_Failure; return(Json(gVal, JsonRequestBehavior.AllowGet)); } catch { gVal.Code = 5; gVal.Error = message_Feedback.Process_Failed; return(Json(gVal, JsonRequestBehavior.AllowGet)); } }
public ActionResult EditStoreAddress(StoreAddressObject storeAddress) { var gVal = new GenericValidator(); try { if (ModelState.IsValid) { var valStatus = ValidateStoreAddress(storeAddress); if (valStatus.Code < 1) { gVal.Code = 0; gVal.Error = valStatus.Error; return(Json(gVal, JsonRequestBehavior.AllowGet)); } if (Session["_storeAddress"] == null) { gVal.Code = -1; gVal.Error = message_Feedback.Session_Time_Out; return(Json(gVal, JsonRequestBehavior.AllowGet)); } var oldStoreAddress = Session["_storeAddress"] as StoreAddressObject; if (oldStoreAddress == null || oldStoreAddress.StoreAddressId < 1) { gVal.Code = -5; gVal.Error = message_Feedback.Session_Time_Out; return(Json(gVal, JsonRequestBehavior.AllowGet)); } oldStoreAddress.StreetNo = storeAddress.StreetNo.Trim(); oldStoreAddress.StoreCityId = storeAddress.StoreCityId; var k = new StoreAddressServices().UpdateStoreAddress(oldStoreAddress); if (k < 1) { gVal.Error = k == -3 ? message_Feedback.Item_Duplicate : message_Feedback.Update_Failure; gVal.Code = 0; return(Json(gVal, JsonRequestBehavior.AllowGet)); } gVal.Code = 5; gVal.Error = message_Feedback.Update_Success; return(Json(gVal, JsonRequestBehavior.AllowGet)); } gVal.Code = -5; gVal.Error = message_Feedback.Process_Failed; return(Json(gVal, JsonRequestBehavior.AllowGet)); } catch { gVal.Code = -1; gVal.Error = message_Feedback.Process_Failed; return(Json(gVal, JsonRequestBehavior.AllowGet)); } }
public ActionResult AddStoreOutlet(StoreOutletObject storeOutlet) { var gVal = new GenericValidator(); try { if (ModelState.IsValid) { var valStatus = ValidateStoreOutlet(storeOutlet); if (valStatus.Code < 1) { gVal.Code = -1; gVal.Error = valStatus.Error; return(Json(gVal, JsonRequestBehavior.AllowGet)); } var storeAddress = new StoreAddressObject { StoreCityId = storeOutlet.StoreAddressObject.StoreCityId, StreetNo = storeOutlet.StoreAddressObject.StreetNo }; var t = new StoreAddressServices().AddStoreAddress(storeAddress); if (t < 1) { gVal.Code = -1; gVal.Error = message_Feedback.Outlet_Address_Error; return(Json(gVal, JsonRequestBehavior.AllowGet)); } storeOutlet.StoreAddressId = t; storeOutlet.DateCreated = DateTime.Now; var k = new StoreOutletServices().AddStoreOutlet(storeOutlet); if (k < 1) { gVal.Error = k == -3 ? message_Feedback.Item_Duplicate : message_Feedback.Insertion_Failure; gVal.Code = -1; return(Json(gVal, JsonRequestBehavior.AllowGet)); } gVal.Code = 5; gVal.Error = message_Feedback.Insertion_Success; return(Json(gVal, JsonRequestBehavior.AllowGet)); } gVal.Code = -5; gVal.Error = message_Feedback.Model_State_Error; return(Json(gVal, JsonRequestBehavior.AllowGet)); } catch { gVal.Code = 0; gVal.Error = message_Feedback.Process_Failed; return(Json(gVal, JsonRequestBehavior.AllowGet)); } }
public ActionResult GetStoreAddressObjects(JQueryDataTableParamModel param) { var gVal = new GenericValidator(); try { IEnumerable <StoreAddressObject> filteredStoreAddressObjects; var countG = new StoreAddressServices().GetObjectCount(); var pagedStoreAddressObjects = GetCities(param.iDisplayLength, param.iDisplayStart); if (!string.IsNullOrEmpty(param.sSearch)) { filteredStoreAddressObjects = new StoreAddressServices().Search(param.sSearch); } else { filteredStoreAddressObjects = pagedStoreAddressObjects; } if (!filteredStoreAddressObjects.Any()) { return(Json(new List <StoreAddressObject>(), JsonRequestBehavior.AllowGet)); } var sortColumnIndex = Convert.ToInt32(Request["iSortCol_0"]); Func <StoreAddressObject, string> orderingFunction = (c => sortColumnIndex == 1 ? c.StreetNo : c.CityName ); var sortDirection = Request["sSortDir_0"]; // asc or desc filteredStoreAddressObjects = sortDirection == "asc" ? filteredStoreAddressObjects.OrderBy(orderingFunction) : filteredStoreAddressObjects.OrderByDescending(orderingFunction); var displayedUserProfilenels = filteredStoreAddressObjects; var result = from c in displayedUserProfilenels select new[] { Convert.ToString(c.StoreAddressId), c.StreetNo, c.CityName }; return(Json(new { param.sEcho, iTotalRecords = countG, iTotalDisplayRecords = filteredStoreAddressObjects.Count(), aaData = result }, JsonRequestBehavior.AllowGet)); } catch (Exception ex) { ErrorLogger.LogError(ex.StackTrace, ex.Source, ex.Message); return(Json(new List <StoreAddressObject>(), JsonRequestBehavior.AllowGet)); } }
public ActionResult AddStoreAddress(StoreAddressObject storeAddress) { var gVal = new GenericValidator(); try { if (ModelState.IsValid) { var valStatus = ValidateStoreAddress(storeAddress); if (valStatus.Code < 1) { gVal.Code = 0; gVal.Error = valStatus.Error; return(Json(gVal, JsonRequestBehavior.AllowGet)); } var k = new StoreAddressServices().AddStoreAddress(storeAddress); if (k < 1) { gVal.Error = k == -3 ? message_Feedback.Item_Duplicate : message_Feedback.Insertion_Failure; gVal.Code = 0; return(Json(gVal, JsonRequestBehavior.AllowGet)); } gVal.Code = k; gVal.Error = message_Feedback.Insertion_Success; return(Json(gVal, JsonRequestBehavior.AllowGet)); } gVal.Code = -1; gVal.Error = message_Feedback.Model_State_Error; return(Json(gVal, JsonRequestBehavior.AllowGet)); } catch { gVal.Code = -1; gVal.Error = message_Feedback.Process_Failed; return(Json(gVal, JsonRequestBehavior.AllowGet)); } }
public ActionResult GetStoreAddress(long id) { var gVal = new GenericValidator(); try { if (id < 1) { return(Json(new StoreAddressObject(), JsonRequestBehavior.AllowGet)); } var storeAddress = new StoreAddressServices().GetStoreAddress(id); if (id < 1) { return(Json(new StoreAddressObject(), JsonRequestBehavior.AllowGet)); } Session["_storeAddress"] = storeAddress; return(Json(storeAddress, JsonRequestBehavior.AllowGet)); } catch (Exception) { return(Json(new StoreAddressObject(), JsonRequestBehavior.AllowGet)); } }
public async Task <ActionResult> EditProfile(EmployeeObject employee) { var gVal = new GenericValidator(); try { var valStatus = ValidateProfile(employee); if (valStatus.Code < 1) { gVal.Code = 0; gVal.Error = valStatus.Error; return(Json(gVal, JsonRequestBehavior.AllowGet)); } if (Session["_employee"] == null) { gVal.Code = -1; gVal.Error = message_Feedback.Session_Time_Out; return(Json(gVal, JsonRequestBehavior.AllowGet)); } var oldEmployee = Session["_employee"] as EmployeeObject; if (oldEmployee == null || oldEmployee.EmployeeId < 1) { gVal.Code = -1; gVal.Error = message_Feedback.Session_Time_Out; return(Json(gVal, JsonRequestBehavior.AllowGet)); } var user = UserManager.FindByEmail(employee.Email); if (user == null) { gVal.Code = -1; gVal.Error = "User information could not be updated."; return(Json(gVal, JsonRequestBehavior.AllowGet)); } if (!string.IsNullOrEmpty(employee.Password)) { if (string.IsNullOrEmpty(employee.OriginalPassword)) { gVal.Code = -1; gVal.Error = "Please provide your original password."; return(Json(gVal, JsonRequestBehavior.AllowGet)); } if (string.IsNullOrEmpty(employee.ConfirmPassword)) { gVal.Code = -1; gVal.Error = "Please provide your password password confirmation."; return(Json(gVal, JsonRequestBehavior.AllowGet)); } if (employee.Password != employee.ConfirmPassword) { gVal.Code = -1; gVal.Error = "The passwords do not match"; return(Json(gVal, JsonRequestBehavior.AllowGet)); } var passwordResult = UserManager.CheckPassword(user, employee.OriginalPassword); if (!passwordResult) { gVal.Code = -1; gVal.Error = "Your original password could not be verified."; return(Json(gVal, JsonRequestBehavior.AllowGet)); } var passwordHash = new PasswordHasher().HashPassword(employee.Password); user.PasswordHash = passwordHash; var result = await UserManager.UpdateAsync(user); if (!result.Succeeded) { gVal.Code = -1; gVal.Error = "User information could not be updated."; return(Json(gVal, JsonRequestBehavior.AllowGet)); } gVal.PasswordUpdated = true; } var address = new StoreAddressObject { StreetNo = employee.StreetNo, StoreAddressId = employee.StoreAddressId, StoreCityId = employee.StoreCityId }; var ad = new StoreAddressServices().UpdateStoreAddress(address); if (ad < 1) { gVal.Code = -1; gVal.Error = message_Feedback.Employee_Address_Update_Error; return(Json(gVal, JsonRequestBehavior.AllowGet)); } oldEmployee.Email = employee.Email; oldEmployee.PhoneNumber = employee.PhoneNumber; oldEmployee.OtherNames = employee.OtherNames; oldEmployee.LastName = employee.LastName; oldEmployee.EmployeeNo = employee.EmployeeNo; oldEmployee.Birthday = employee.Birthday; oldEmployee.StoreAddressId = employee.StoreAddressId; oldEmployee.Birthday = employee.Birthday; var k = new EmployeeServices().UpdateEmployeeProfile(oldEmployee); if (k < 1) { gVal.Error = k == -3 ? "A different user with similar phone number already exists!" : message_Feedback.Update_Failure; gVal.Code = -1; return(Json(gVal, JsonRequestBehavior.AllowGet)); } gVal.Code = 5; gVal.Error = "Your profile was successfully updated."; return(Json(gVal, JsonRequestBehavior.AllowGet)); } catch { gVal.Code = -1; gVal.Error = message_Feedback.Process_Failed; return(Json(gVal, JsonRequestBehavior.AllowGet)); } }
public async Task <ActionResult> EditEmployee(EmployeeObject employee, string subdomain) { var storeSetting = new SessionHelpers().GetStoreInfo(subdomain); if (storeSetting == null || storeSetting.StoreId < 1) { return(Json(new CustomerObject(), JsonRequestBehavior.AllowGet)); } var gVal = new GenericValidator(); try { var valStatus = ValidateEmployee(employee); if (valStatus.Code < 1) { gVal.Code = 0; gVal.Error = valStatus.Error; return(Json(gVal, JsonRequestBehavior.AllowGet)); } if (Session["_employee"] == null) { gVal.Code = -1; gVal.Error = message_Feedback.Session_Time_Out; return(Json(gVal, JsonRequestBehavior.AllowGet)); } var oldEmployee = Session["_employee"] as EmployeeObject; if (oldEmployee == null || oldEmployee.EmployeeId < 1) { gVal.Code = -1; gVal.Error = message_Feedback.Session_Time_Out; return(Json(gVal, JsonRequestBehavior.AllowGet)); } var user = UserManager.FindByEmail(employee.Email); if (user == null) { gVal.Code = -1; gVal.Error = "User information could not be updated."; return(Json(gVal, JsonRequestBehavior.AllowGet)); } var roleManager = new RoleManager <IdentityRole>(new RoleStore <IdentityRole>(new ApplicationDbContext(storeSetting.EntityConnectionString))); var role = roleManager.FindById(employee.RoleId); if (role == null) { gVal.Code = -1; gVal.Error = "User information could not be updated."; return(Json(gVal, JsonRequestBehavior.AllowGet)); } var userRoles = UserManager.GetRoles(oldEmployee.AspNetUserId).ToList(); if (!userRoles.Any()) { return(Json(new EmployeeObject(), JsonRequestBehavior.AllowGet)); } if (!string.IsNullOrEmpty(employee.Password)) { var passwordHash = new PasswordHasher().HashPassword(employee.Password); user.PasswordHash = passwordHash; var result = await UserManager.UpdateAsync(user); if (!result.Succeeded) { gVal.Code = -1; gVal.Error = "User information could not be updated."; return(Json(gVal, JsonRequestBehavior.AllowGet)); } } var address = new StoreAddressObject { StreetNo = employee.StreetNo, StoreAddressId = employee.StoreAddressId, StoreCityId = employee.StoreCityId }; var ad = new StoreAddressServices().UpdateStoreAddress(address); if (ad < 1) { gVal.Code = -1; gVal.Error = message_Feedback.Employee_Address_Update_Error; return(Json(gVal, JsonRequestBehavior.AllowGet)); } oldEmployee.Email = employee.Email; oldEmployee.PhoneNumber = employee.PhoneNumber; oldEmployee.OtherNames = employee.OtherNames; oldEmployee.LastName = employee.LastName; oldEmployee.Status = employee.Status; oldEmployee.EmployeeNo = employee.EmployeeNo; oldEmployee.RoleId = employee.RoleId; oldEmployee.DateHired = employee.DateHired; oldEmployee.DateLeft = employee.DateLeft; oldEmployee.StoreOutletId = employee.StoreOutletId; oldEmployee.StoreAddressId = employee.StoreAddressId; oldEmployee.StoreDepartmentId = employee.StoreDepartmentId; var k = new EmployeeServices().UpdateEmployee(oldEmployee); if (k < 1) { gVal.Error = k == -3 ? "A different user with similar phone number already exists!" : message_Feedback.Update_Failure; gVal.Code = 0; return(Json(gVal, JsonRequestBehavior.AllowGet)); } var userRole = userRoles[0]; if (role.Name.ToLower() != userRole.ToLower()) { UserManager.RemoveFromRole(oldEmployee.AspNetUserId, userRole); UserManager.AddToRole(oldEmployee.AspNetUserId, role.Name); } gVal.Code = 5; gVal.Error = message_Feedback.Update_Success; return(Json(gVal, JsonRequestBehavior.AllowGet)); } catch { gVal.Code = -1; gVal.Error = message_Feedback.Process_Failed; return(Json(gVal, JsonRequestBehavior.AllowGet)); } }
public async Task <ActionResult> AddEmployee(EmployeeObject employee, string subdomain) { var storeSetting = new SessionHelpers().GetStoreInfo(subdomain); if (storeSetting == null || storeSetting.StoreId < 1) { return(Json(new CustomerObject(), JsonRequestBehavior.AllowGet)); } var gVal = new GenericValidator(); try { var valStatus = ValidateEmployee(employee); if (valStatus.Code < 1) { gVal.Code = 0; gVal.Error = valStatus.Error; return(Json(gVal, JsonRequestBehavior.AllowGet)); } if (string.IsNullOrEmpty(employee.Password)) { gVal.Code = -1; gVal.Error = "ERROR: Please Provide Password."; return(Json(gVal, JsonRequestBehavior.AllowGet)); } var checkDuplicatePhoneNumber = new EmployeeServices().VerifyPhoneNumber(employee.PhoneNumber); if (checkDuplicatePhoneNumber) { gVal.Code = -1; gVal.Error = "A user with the same phone number already exists."; return(Json(gVal, JsonRequestBehavior.AllowGet)); } var address = new StoreAddressObject { StreetNo = employee.StreetNo, StoreCityId = employee.StoreCityId }; var ad = new StoreAddressServices().AddStoreAddress(address); if (ad < 1) { gVal.Code = -1; gVal.Error = message_Feedback.Employee_Address_Add_Error; return(Json(gVal, JsonRequestBehavior.AllowGet)); } UserManager.UserLockoutEnabledByDefault = false; var status = (int)EmployeeStatus.Active; var user = new ApplicationUser { UserName = employee.Email, Email = employee.Email, PhoneNumber = employee.PhoneNumber, UserInfo = new ApplicationDbContext.UserProfile { LastName = employee.LastName, OtherNames = employee.OtherNames, IsActive = employee.Status == status, MobileNumber = employee.PhoneNumber, ContactEmail = employee.Email } }; var result = await UserManager.CreateAsync(user, employee.Password); if (!result.Succeeded) { gVal.Code = -1; gVal.Error = result.Errors.ToList()[0]; return(Json(gVal, JsonRequestBehavior.AllowGet)); } var roleManager = new RoleManager <IdentityRole>(new RoleStore <IdentityRole>(new ApplicationDbContext(storeSetting.EntityConnectionString))); var role = roleManager.FindById(employee.RoleId); if (role == null) { gVal.Code = -1; gVal.Error = "User information could not be updated."; return(Json(gVal, JsonRequestBehavior.AllowGet)); } UserManager.AddToRole(user.Id, role.Name); //todo: change to dynamic outletid employee.StoreAddressId = ad; //employee.StoreOutletId = 1; var employeeNo = GenerateEmpoyeeNo(); if (string.IsNullOrEmpty(employeeNo)) { gVal.Code = -1; gVal.Error = message_Feedback.Process_Failed; return(Json(gVal, JsonRequestBehavior.AllowGet)); } employee.EmployeeNo = employeeNo; employee.UserId = user.UserInfo.Id; var k = new EmployeeServices().AddEmployee(employee); if (k < 1) { gVal.Error = k == -3 ? message_Feedback.Item_Duplicate : message_Feedback.Insertion_Failure; gVal.Code = 0; return(Json(gVal, JsonRequestBehavior.AllowGet)); } gVal.Code = k; gVal.Error = message_Feedback.Insertion_Success; return(Json(gVal, JsonRequestBehavior.AllowGet)); } catch { gVal.Code = -1; gVal.Error = message_Feedback.Process_Failed; return(Json(gVal, JsonRequestBehavior.AllowGet)); } }
public ActionResult EditStoreOutlet(StoreOutletObject storeOutlet) { var gVal = new GenericValidator(); try { if (ModelState.IsValid) { var valStatus = ValidateStoreOutlet(storeOutlet); if (valStatus.Code < 1) { gVal.Code = -1; gVal.Error = valStatus.Error; return(Json(gVal, JsonRequestBehavior.AllowGet)); } if (Session["_storeOutlet"] == null) { gVal.Code = -1; gVal.Error = message_Feedback.Session_Time_Out; return(Json(gVal, JsonRequestBehavior.AllowGet)); } var oldStoreOutlet = Session["_storeOutlet"] as StoreOutletObject; if (oldStoreOutlet == null || oldStoreOutlet.StoreOutletId < 1) { gVal.Code = -1; gVal.Error = message_Feedback.Session_Time_Out; return(Json(gVal, JsonRequestBehavior.AllowGet)); } oldStoreOutlet.OutletName = storeOutlet.OutletName; oldStoreOutlet.DefaultTax = storeOutlet.DefaultTax; oldStoreOutlet.FacebookHandle = storeOutlet.FacebookHandle; var storeAddress = new StoreAddressObject { StoreCityId = storeOutlet.StoreAddressObject.StoreCityId, StreetNo = storeOutlet.StoreAddressObject.StreetNo, StoreAddressId = oldStoreOutlet.StoreAddressId }; var t = new StoreAddressServices().UpdateStoreAddress(storeAddress); if (t < 1) { gVal.Code = -1; gVal.Error = message_Feedback.Outlet_Address_Error; return(Json(gVal, JsonRequestBehavior.AllowGet)); } oldStoreOutlet.IsOperational = storeOutlet.IsOperational; if (!string.IsNullOrEmpty(oldStoreOutlet.FacebookHandle)) { oldStoreOutlet.FacebookHandle = storeOutlet.FacebookHandle; } if (!string.IsNullOrEmpty(oldStoreOutlet.TwitterHandle)) { oldStoreOutlet.TwitterHandle = storeOutlet.TwitterHandle; } var k = new StoreOutletServices().UpdateStoreOutlet(oldStoreOutlet); if (k < 1) { gVal.Code = -1; gVal.Error = k == -3 ? message_Feedback.Item_Duplicate : message_Feedback.Update_Failure; return(Json(gVal, JsonRequestBehavior.AllowGet)); } gVal.Code = 5; gVal.Error = message_Feedback.Update_Success; return(Json(gVal, JsonRequestBehavior.AllowGet)); } gVal.Code = -1; gVal.Error = message_Feedback.Model_State_Error; return(Json(gVal, JsonRequestBehavior.AllowGet)); } catch { gVal.Code = -1; gVal.Error = message_Feedback.Process_Failed; return(Json(gVal, JsonRequestBehavior.AllowGet)); } }