// the following code connects with the update function in the DataAccess logic through the BusinessLogic private void UpdateOwner(int id, string ownername, string petname, int petage, string contactphone, string firstname, string lastname, string username, string password, int age, string email, string role) { try { using (var owners = new OwnersBusiness()) { var entity = new OwnersEntity(); entity.OwnerID = id; entity.OwnerName = ownername; entity.PetName = petname; entity.PetAge = petage; entity.ContactPhone = contactphone; entity.FirstName = firstname; entity.LastName = lastname; entity.Username = username; entity.Password = password; entity.Age = age; entity.Email = email; entity.Role = role; var opSuccessful = owners.UpdateOwner(entity); } } catch (Exception ex) { //Log exception error _loggingHandler.LogEntry(ExceptionHandler.GetExceptionMessageFormatted(ex), true); } }
private void Update(int id, string ownername, string petname, int age, string contactphone) { try { using (var owners = new OwnersBusiness()) { var entity = new OwnersEntity(); entity.OwnerID = id; entity.OwnerName = ownername; entity.PetName = petname; entity.PetAge = age; entity.ContactPhone = contactphone; var opSuccessful = owners.UpdateOwner(entity); var resultMessage = opSuccessful ? "Done Successfully" : "Error happened or no Owner found to update"; MessageBox.Show(resultMessage, "Success", MessageBoxButtons.OK); } } catch (Exception ex) { //Log exception error _loggingHandler.LogEntry(ExceptionHandler.GetExceptionMessageFormatted(ex), true); MessageBox.Show("UserInterface:OwnersForm::Update::Error occured." + Environment.NewLine + ex.Message, "Error", MessageBoxButtons.OK); } }
public ActionResult Login(LoginModel info) { using (BusinessLogic.UsersBusiness ctx = new BusinessLogic.UsersBusiness()) { UsersEntity user = ctx.FindUserByUsername(info.Username); if (user == null) { info.message = $"The Username '{info.Username}' does not exist in the database"; return(View(info)); } string actual = user.Password; //string potential = user.Salt + info.Password; string potential = info.Password; bool validateduser = false; if (info.Username.ToLower() == "admin") { validateduser = potential == actual; } else { // check password hash validateduser = System.Web.Helpers.Crypto.VerifyHashedPassword(actual, potential); } if (validateduser) { Session["AUTHUsername"] = user.Username; Session["AUTHRole"] = user.Role; Session["AUTHUserID"] = user.UserID; Session["ChosenOwnerID"] = 0; if (user.Role == "Owner") { using (BusinessLogic.OwnersBusiness ctx2 = new BusinessLogic.OwnersBusiness()) { OwnersEntity owner = ctx2.FindOwnerByUserId(user.UserID); Session["AUTHOwnerID"] = owner.OwnerID; return(Redirect("~/Owners/Details/" + owner.OwnerID)); } } else if (user.Role == "Sitter") { using (BusinessLogic.SittersBusiness ctx2 = new BusinessLogic.SittersBusiness()) { SittersEntity sitter = ctx2.FindSitterByUserId(user.UserID); Session["AUTHSitterID"] = sitter.SitterID; return(Redirect("~/Sitters/Details/" + sitter.SitterID)); } } else if (user.Role == "Admin") { return(Redirect("~/Users/ListAll")); } } info.message = "The password was incorrect"; return(View(info)); } }
// Business Logic pass through code to Update Owner public bool UpdateOwner(OwnersEntity entity) { try { bool bOpDoneSuccessfully; using (var repository = new OwnersRepository()) { bOpDoneSuccessfully = repository.Update(entity); } return(bOpDoneSuccessfully); } catch (Exception ex) { //Log exception error _loggingHandler.LogEntry(ExceptionHandler.GetExceptionMessageFormatted(ex), true); throw new Exception("BusinessLogic:OwnersBusiness::UpdateOwner::Error occured.", ex); } }