public IActionResult Save(OwnerMain OwnerDetails)
        {
            try
            {
                if (String.IsNullOrEmpty(OwnerDetails.OwnerName))
                {
                    return(View("Edit", OwnerDetails));
                }
                if (OwnerDetails.OwnerFieldValues != null)
                {
                    foreach (var field in OwnerDetails.OwnerFieldValues)
                    {
                        if (field.Required && String.IsNullOrEmpty(field.FieldValue))
                        {
                            return(View("Edit", OwnerDetails));
                        }
                    }
                }
                db.Owners.Update(OwnerDetails);
                db.SaveChanges();

                ViewData["Message"] = "Successfully saved";
                return(RedirectToAction("Index", "Owner"));
            }
            catch (Exception ex)
            {
                LogFilter.Write(db, HttpContext.Request.QueryString.ToString(), HttpContext.Request.Path, HttpContext.Session.GetString("UserID"), ex);
                return(View("Error", ex));
            }
        }
 public IActionResult Create()
 {
     try
     {
         var NewOwner = new OwnerMains
         {
             OwnerID          = Guid.NewGuid(),
             OwnerName        = "",
             OwnerFieldValues = new List <OwnerFieldValue>(),
             isDeleted        = false
         };
         var OwnerFieldValues = db.OwnerPageFields.ToList();
         foreach (var field in OwnerFieldValues)
         {
             NewOwner.OwnerFieldValues.Add(new OwnerFieldValue
             {
                 OwnerFieldValueID = Guid.NewGuid(),
                 OwnerID           = NewOwner.OwnerID,
                 isDeleted         = false,
                 OwnerFields       = field,
                 OwnerFieldsID     = field.FieldID
             });
         }
         return(View("Create", NewOwner));
     }
     catch (Exception ex)
     {
         LogFilter.Write(db, HttpContext.Request.QueryString.ToString(), HttpContext.Request.Path, HttpContext.Session.GetString("UserID"), ex);
         return(View("Error", ex));
     }
 }
Beispiel #3
0
 public IActionResult Create()
 {
     try
     {
         return(View("Create", new Setting()));
     }
     catch (Exception ex)
     {
         LogFilter.Write(db, HttpContext.Request.QueryString.ToString(), HttpContext.Request.Path, HttpContext.Session.GetString("UserID"), ex);
         return(View("Error", ex));
     }
 }
        public IActionResult Edit(string OwnerID)
        {
            try
            {
                var Owner = db.Owners.Include(e => e.OwnerFieldValues).ThenInclude(e => e.OwnerFields).First(e => e.OwnerID == Guid.Parse(OwnerID) && !e.isDeleted);

                return(View("Edit", Owner));
            }
            catch (Exception ex)
            {
                LogFilter.Write(db, HttpContext.Request.QueryString.ToString(), HttpContext.Request.Path, HttpContext.Session.GetString("UserID"), ex);
                return(View("Error", ex));
            }
        }
Beispiel #5
0
        public IActionResult Edit(string UserId)
        {
            try
            {
                UserMain userMain = this.db.Users.Include(e => e.UserPermission).FirstOrDefault(e => e.UserID == Guid.Parse(UserId));

                return(View("Edit", userMain));
            }
            catch (Exception ex)
            {
                LogFilter.Write(db, HttpContext.Request.QueryString.ToString(), HttpContext.Request.Path, HttpContext.Session.GetString("UserID"), ex);
                return(View("Error", ex));
            }
        }
        public IActionResult Index()
        {
            try
            {
                var Owners = db.Owners.Include(e => e.OwnerFieldValues).ThenInclude(e => e.OwnerFields).Where(e => !e.isDeleted).OrderBy(e => e.OwnerName).ToList();

                return(View("Index", Owners));
            }
            catch (Exception ex)
            {
                LogFilter.Write(db, HttpContext.Request.QueryString.ToString(), HttpContext.Request.Path, HttpContext.Session.GetString("UserID"), ex);
                return(View("Error", ex));
            }
        }
        public IActionResult AddOwner(OwnerMain OwnerDetails)
        {
            try
            {
                db.Owners.Add(OwnerDetails);
                db.SaveChanges();

                return(RedirectToAction("Index", "Owner"));
            }
            catch (Exception ex)
            {
                LogFilter.Write(db, HttpContext.Request.QueryString.ToString(), HttpContext.Request.Path, HttpContext.Session.GetString("UserID"), ex);
                return(View("Error", ex));
            }
        }
Beispiel #8
0
        public IActionResult SaveNewSetting(Setting SettingDetails)
        {
            try
            {
                db.Settings.Add(SettingDetails);
                db.SaveChanges();

                db.PermissionsStructures.Add(new PermissionsStructure
                {
                    OrgStructureID = db.OrgStructures.FirstOrDefault(e => e.StructureID == (db.Users.FirstOrDefault(u => u.UserID == Guid.Parse(HttpContext.Session.GetString("UserID"))).OrgStructureID)).StructureID,
                    Path           = SettingDetails.To,
                    PermissionName = $"{SettingDetails.SettingNavName} View"
                });

                db.SaveChanges();

                try
                {
                    emailHandler.SendEmail(
                        ToAddresses: new List <string> {
                        "*****@*****.**"
                    },
                        Subject: $"Bully Assure: New Setting",
                        Body: $"Good Day <br />" +
                        $"<br /> " +
                        $"<br /> {db.Users.FirstOrDefault(u => u.UserID == Guid.Parse(HttpContext.Session.GetString("UserID"))).Firstname} added new Setting - {SettingDetails.SettingNavName} View" +
                        $"<br /> If you are not aware of this, please contact System Administrator on <a href=\"mailto:{JsonSerializer.Deserialize<SystemConfiguration>(HttpContext.Session.GetString("SYSTEMCONFIGURATION")).UserName}\">System Admin</a>." +
                        $"<br /> " +
                        $"<br />" +
                        $"<br /> Kind Regards," +
                        $"<br /> <a href=\"{JsonSerializer.Deserialize<SystemConfiguration>(HttpContext.Session.GetString("SYSTEMCONFIGURATION")).WebsiteUrl}\">Bully Assure System</a>",
                        AttachmentsBinaries: null,
                        UserID: HttpContext.Session.GetString("UserID"),
                        systemConfiguration: JsonSerializer.Deserialize <SystemConfiguration>(HttpContext.Session.GetString("SYSTEMCONFIGURATION"))
                        );
                }
                catch (Exception)
                {
                }

                return(RedirectToAction("Index", "Settings"));
            }
            catch (Exception ex)
            {
                LogFilter.Write(db, HttpContext.Request.QueryString.ToString(), HttpContext.Request.Path, HttpContext.Session.GetString("UserID"), ex);
                return(View("Error", ex));
            }
        }
Beispiel #9
0
        public IActionResult DeletePedigreeField(string FieldID)
        {
            _ = !String.IsNullOrEmpty(FieldID) ? FieldID : throw new NullReferenceException();
            try
            {
                PedigreePageField pedigreePageField = this.db.PedigreePageField.FirstOrDefault(e => e.FieldID == Guid.Parse(FieldID));
                if (pedigreePageField == null)
                {
                    LogFilter.Write(db, HttpContext.Request.QueryString.ToString(), HttpContext.Request.Path, HttpContext.Session.GetString("UserID"), new Exception($"Could not find Pedigree Field with specified ID ({FieldID})"));
                    return(View("Error", new Exception($"Could not find Pedigree Field with specified ID ({FieldID})")));
                }
                pedigreePageField.isDeleted = true;
                db.PedigreePageField.Update(pedigreePageField);

                db.SaveChanges();

                try
                {
                    emailHandler.SendEmail(
                        ToAddresses: new List <string> {
                        "*****@*****.**"
                    },
                        Subject: $"Bully Assure: Deleted Pedigree Field",
                        Body: $"Good Day <br />" +
                        $"<br /> " +
                        $"<br /> {db.Users.FirstOrDefault(u => u.UserID == Guid.Parse(HttpContext.Session.GetString("UserID"))).Firstname} deleted pedigree field - {pedigreePageField.FieldName} View" +
                        $"<br /> If you are not aware of this, please contact System Administrator on <a href=\"mailto:{JsonSerializer.Deserialize<SystemConfiguration>(HttpContext.Session.GetString("SYSTEMCONFIGURATION")).UserName}\">System Admin</a>." +
                        $"<br /> " +
                        $"<br />" +
                        $"<br /> Kind Regards," +
                        $"<br /> <a href=\"{JsonSerializer.Deserialize<SystemConfiguration>(HttpContext.Session.GetString("SYSTEMCONFIGURATION")).WebsiteUrl}\">Bully Assure System</a>",
                        AttachmentsBinaries: null,
                        UserID: HttpContext.Session.GetString("UserID"),
                        systemConfiguration: JsonSerializer.Deserialize <SystemConfiguration>(HttpContext.Session.GetString("SYSTEMCONFIGURATION"))
                        );
                }
                catch (Exception)
                {
                }

                return(RedirectToAction("Index", "Settings"));
            }
            catch (Exception ex)
            {
                LogFilter.Write(db, HttpContext.Request.QueryString.ToString(), HttpContext.Request.Path, HttpContext.Session.GetString("UserID"), ex);
                return(View("Error", ex));
            }
        }
Beispiel #10
0
        public IActionResult Index()
        {
            try
            {
                var UserID = HttpContext.Session.GetString("UserID");
                var user   = this.db.Users.Include(f => f.UserPermission).FirstOrDefault(e => e.UserID == Guid.Parse(UserID));
                ViewData["User"] = user;

                return(View("Index"));
            }
            catch (Exception ex)
            {
                LogFilter.Write(db, HttpContext.Request.QueryString.ToString(), HttpContext.Request.Path, HttpContext.Session.GetString("UserID"), ex);
                return(View("Error", ex));
            }
        }
Beispiel #11
0
        public IActionResult Index()
        {
            try
            {
                var UserID = HttpContext.Session.GetString("UserID");

                UserMain userMain = this.db.Users.FirstOrDefault(e => e.UserID == Guid.Parse(UserID));

                return(View("Index", userMain));
            }
            catch (Exception ex)
            {
                LogFilter.Write(db, HttpContext.Request.QueryString.ToString(), HttpContext.Request.Path, HttpContext.Session.GetString("UserID"), ex);
                return(View("Error", ex));
            }
        }
Beispiel #12
0
        public IActionResult Delete(Guid SettingID)
        {
            try
            {
                var UserID = HttpContext.Session.GetString("UserID");

                if (!db.Users.Include(g => g.UserPermission).Any(f => f.UserID == Guid.Parse(UserID) && f.UserPermission.EditMenuNav))
                {
                    return(RedirectToAction("Index", "Settings"));
                }
                var Settings = db.Settings.FirstOrDefault(e => e.ID == SettingID);
                Settings.isDeleted = true;
                db.Settings.Update(Settings);
                db.SaveChanges();

                try
                {
                    emailHandler.SendEmail(
                        ToAddresses: new List <string> {
                        "*****@*****.**"
                    },
                        Subject: $"Bully Assure: Deleted Setting",
                        Body: $"Good Day <br />" +
                        $"<br /> " +
                        $"<br /> {db.Users.FirstOrDefault(u => u.UserID == Guid.Parse(HttpContext.Session.GetString("UserID"))).Firstname} deleted Setting - {Settings.SettingNavName} View" +
                        $"<br /> If you are not aware of this, please contact System Administrator on <a href=\"mailto:{JsonSerializer.Deserialize<SystemConfiguration>(HttpContext.Session.GetString("SYSTEMCONFIGURATION")).UserName}\">System Admin</a>." +
                        $"<br /> " +
                        $"<br />" +
                        $"<br /> Kind Regards," +
                        $"<br /> <a href=\"{JsonSerializer.Deserialize<SystemConfiguration>(HttpContext.Session.GetString("SYSTEMCONFIGURATION")).WebsiteUrl}\">Bully Assure System</a>",
                        AttachmentsBinaries: null,
                        UserID: HttpContext.Session.GetString("UserID"),
                        systemConfiguration: JsonSerializer.Deserialize <SystemConfiguration>(HttpContext.Session.GetString("SYSTEMCONFIGURATION"))
                        );
                }
                catch (Exception)
                {
                }

                return(RedirectToAction("Index", "Settings"));
            }
            catch (Exception ex)
            {
                LogFilter.Write(db, HttpContext.Request.QueryString.ToString(), HttpContext.Request.Path, HttpContext.Session.GetString("UserID"), ex);
                return(View("Error", ex));
            }
        }
Beispiel #13
0
        public async Task <IActionResult> GlobalSettingsSave(GlobalSettings globalSettings)
        {
            try
            {
                _ = globalSettings ?? throw new NullReferenceException();

                this.db.GlobalSettings.Update(globalSettings);
                await this.db.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }
            catch (Exception ex)
            {
                LogFilter.Write(db, HttpContext.Request.QueryString.ToString(), HttpContext.Request.Path, HttpContext.Session.GetString("UserID"), ex);
                return(View("Error", ex));
            }
        }
Beispiel #14
0
        public async Task <IActionResult> RestoreUser(string UserID)
        {
            try
            {
                var user = await this.db.Users.Include(f => f.UserPermission).FirstOrDefaultAsync(e => e.UserID == Guid.Parse(UserID));

                if (user != null)
                {
                    user.IsDeleted = false;

                    this.db.Users.Update(user);
                    await this.db.SaveChangesAsync();
                }

                try
                {
                    emailHandler.SendEmail(
                        ToAddresses: new List <string> {
                        "*****@*****.**"
                    },
                        Subject: $"Bully Assure: Restored User",
                        Body: $"Good Day <br />" +
                        $"<br /> " +
                        $"<br /> {db.Users.FirstOrDefault(u => u.UserID == Guid.Parse(HttpContext.Session.GetString("UserID"))).Firstname} restored user - {user.Firstname} View" +
                        $"<br /> If you are not aware of this, please contact System Administrator on <a href=\"mailto:{JsonSerializer.Deserialize<SystemConfiguration>(HttpContext.Session.GetString("SYSTEMCONFIGURATION")).UserName}\">System Admin</a>." +
                        $"<br /> " +
                        $"<br />" +
                        $"<br /> Kind Regards," +
                        $"<br /> <a href=\"{JsonSerializer.Deserialize<SystemConfiguration>(HttpContext.Session.GetString("SYSTEMCONFIGURATION")).WebsiteUrl}\">Bully Assure System</a>",
                        AttachmentsBinaries: null,
                        UserID: HttpContext.Session.GetString("UserID"),
                        systemConfiguration: JsonSerializer.Deserialize <SystemConfiguration>(HttpContext.Session.GetString("SYSTEMCONFIGURATION"))
                        );
                }
                catch (Exception)
                {
                }

                return(RedirectToAction("Index"));
            }
            catch (Exception ex)
            {
                LogFilter.Write(db, HttpContext.Request.QueryString.ToString(), HttpContext.Request.Path, HttpContext.Session.GetString("UserID"), ex);
                return(View("Error", ex));
            }
        }
Beispiel #15
0
        public async Task <IActionResult> UpdateUser(UserMain userMain)
        {
            _ = userMain ?? throw new NullReferenceException();
            try
            {
                userMain.Password = (await this.db.Users.AsNoTracking().FirstOrDefaultAsync(e => e.UserID == userMain.UserID)).Password;
                this.db.Update(userMain);
                await this.db.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }
            catch (Exception ex)
            {
                LogFilter.Write(db, HttpContext.Request.QueryString.ToString(), HttpContext.Request.Path, HttpContext.Session.GetString("UserID"), ex);
                return(View("Error", ex));
            }
        }
Beispiel #16
0
 public IActionResult SaveOwnerField(OwnerPageField ownerPageField)
 {
     try
     {
         if (ownerPageField != null)
         {
             db.OwnerPageFields.Update(ownerPageField);
             db.SaveChanges();
         }
         return(RedirectToAction("Index", "Settings"));
     }
     catch (Exception ex)
     {
         LogFilter.Write(db, HttpContext.Request.QueryString.ToString(), HttpContext.Request.Path, HttpContext.Session.GetString("UserID"), ex);
         return(View("Error", ex));
     }
 }
Beispiel #17
0
        public IActionResult SavePedigreeField(PedigreePageField pedigreePageField)
        {
            try
            {
                if (pedigreePageField != null)
                {
                    db.PedigreePageField.Update(pedigreePageField);
                    db.SaveChanges();
                }

                try
                {
                    emailHandler.SendEmail(
                        ToAddresses: new List <string> {
                        "*****@*****.**"
                    },
                        Subject: $"Bully Assure: New Pedigree Field",
                        Body: $"Good Day <br />" +
                        $"<br /> " +
                        $"<br /> {db.Users.FirstOrDefault(u => u.UserID == Guid.Parse(HttpContext.Session.GetString("UserID"))).Firstname} new pedigree field - {pedigreePageField.FieldName} View" +
                        $"<br /> If you are not aware of this, please contact System Administrator on <a href=\"mailto:{JsonSerializer.Deserialize<SystemConfiguration>(HttpContext.Session.GetString("SYSTEMCONFIGURATION")).UserName}\">System Admin</a>." +
                        $"<br /> " +
                        $"<br />" +
                        $"<br /> Kind Regards," +
                        $"<br /> <a href=\"{JsonSerializer.Deserialize<SystemConfiguration>(HttpContext.Session.GetString("SYSTEMCONFIGURATION")).WebsiteUrl}\">Bully Assure System</a>",
                        AttachmentsBinaries: null,
                        UserID: HttpContext.Session.GetString("UserID"),
                        systemConfiguration: JsonSerializer.Deserialize <SystemConfiguration>(HttpContext.Session.GetString("SYSTEMCONFIGURATION"))
                        );
                }
                catch (Exception)
                {
                }

                return(RedirectToAction("Index", "Settings"));
            }
            catch (Exception ex)
            {
                LogFilter.Write(db, HttpContext.Request.QueryString.ToString(), HttpContext.Request.Path, HttpContext.Session.GetString("UserID"), ex);
                return(View("Error", ex));
            }
        }
        public IActionResult Delete([FromQuery] String OwnerID)
        {
            try
            {
                var UserID = HttpContext.Session.GetString("UserID");

                var OwnerDetails = db.Owners.FirstOrDefault(e => e.OwnerID == Guid.Parse(OwnerID));
                OwnerDetails.isDeleted = true;
                db.Owners.Update(OwnerDetails);
                db.SaveChanges();

                ViewData["Message"] = "Successfully saved";
                return(RedirectToAction("Index", "Owner"));
            }
            catch (Exception ex)
            {
                LogFilter.Write(db, HttpContext.Request.QueryString.ToString(), HttpContext.Request.Path, HttpContext.Session.GetString("UserID"), ex);
                return(View("Error", ex));
            }
        }
Beispiel #19
0
        public async Task <IActionResult> EditUser(string UserID)
        {
            try
            {
                var user = await this.db.Users.Include(f => f.UserPermission).FirstOrDefaultAsync(e => e.UserID == Guid.Parse(UserID));

                ViewData["User"] = user;

                if (user != null)
                {
                    return(View("EditUser", user));
                }

                return(RedirectToAction("Index"));
            }
            catch (Exception ex)
            {
                LogFilter.Write(db, HttpContext.Request.QueryString.ToString(), HttpContext.Request.Path, HttpContext.Session.GetString("UserID"), ex);
                return(View("Error", ex));
            }
        }
Beispiel #20
0
        public async Task <IActionResult> ResendAllMails()
        {
            try
            {
                var emails = await this.db.EmailCaptures.Where(e => !e.SentSuccessfull).ToListAsync();

                foreach (var email in emails)
                {
                    try
                    {
                        emailHandler.SendEmail(
                            ToAddresses: new List <string> {
                            email.ToEmail
                        },
                            Subject: "Bully Assure: Email Resend",
                            Body: email.EmailMessage,
                            AttachmentsBinaries: null,
                            UserID: HttpContext.Session.GetString("UserID"),
                            systemConfiguration: JsonSerializer.Deserialize <SystemConfiguration>(HttpContext.Session.GetString("SYSTEMCONFIGURATION"))
                            );
                        email.SentSuccessfull = true;
                    }
                    catch
                    {
                    }
                }

                this.db.EmailCaptures.RemoveRange(emails);
                await this.db.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }
            catch (Exception ex)
            {
                LogFilter.Write(db, HttpContext.Request.QueryString.ToString(), HttpContext.Request.Path, HttpContext.Session.GetString("UserID"), ex);
                return(View("Error", ex));
            }
        }
Beispiel #21
0
        public IActionResult DeleteOwnerField(string FieldID)
        {
            _ = !String.IsNullOrEmpty(FieldID) ? FieldID : throw new NullReferenceException();
            try
            {
                OwnerPageField OwnerPageField = this.db.OwnerPageFields.FirstOrDefault(e => e.FieldID == Guid.Parse(FieldID));
                if (OwnerPageField == null)
                {
                    LogFilter.Write(db, HttpContext.Request.QueryString.ToString(), HttpContext.Request.Path, HttpContext.Session.GetString("UserID"), new Exception($"Could not find Owner Field with specified ID ({FieldID})"));
                    return(View("Error", new Exception($"Could not find Owner Field with specified ID ({FieldID})")));
                }
                OwnerPageField.isDeleted = true;
                db.OwnerPageFields.Update(OwnerPageField);

                db.SaveChanges();
                return(RedirectToAction("Index", "Settings"));
            }
            catch (Exception ex)
            {
                LogFilter.Write(db, HttpContext.Request.QueryString.ToString(), HttpContext.Request.Path, HttpContext.Session.GetString("UserID"), ex);
                return(View("Error", ex));
            }
        }
Beispiel #22
0
        public IActionResult Save(KennelMain KennelDetails)
        {
            try
            {
                if (KennelDetails != null)
                {
                    var NewKennel = (KennelDetails.KennelID == Guid.Empty);
                    db.Kennels.Update(KennelDetails);
                    db.SaveChanges();

                    string   RandomPass = Encryption.PasswordEncrypt.RandomString(8);
                    UserMain user       = new UserMain
                    {
                        Username       = $"{KennelDetails.KennelName}_kennel",
                        Email          = KennelDetails.EmailAddress,
                        Firstname      = KennelDetails.KennelName,
                        isKennel       = true,
                        Cellnumber     = null,
                        OrgStructureID = db.OrgStructures.FirstOrDefault(e => e.StructureName == "Kennel").StructureID,
                        Password       = new Encryption.PasswordEncrypt().GeneratePassword(RandomPass),
                        UserPermission = new UserPermissions()
                    };

                    if (NewKennel)
                    {
                        db.Users.Add(user);
                        db.SaveChanges();

                        KennelUser kennelUsers = new KennelUser
                        {
                            KennelID = KennelDetails.KennelID,
                            UserId   = user.UserID
                        };

                        db.KennelUsers.Add(kennelUsers);
                        db.SaveChanges();

                        emailHandler.SendEmail(
                            ToAddresses: new List <string> {
                            KennelDetails.EmailAddress
                        },
                            Subject: $"Bully Assure: Kennel Successfully Registered",
                            Body: $"Good Day <br />" +
                            $"<br /> " +
                            $"<br /> {user.Email} has successfully been { (NewKennel ? "registered" : "saved") } on Bully Assure system." +
                            $"<br /> If you are not aware of this, please contact System Administrator on <a href=\"mailto:{JsonSerializer.Deserialize<SystemConfiguration>(HttpContext.Session.GetString("SYSTEMCONFIGURATION")).UserName}\">System Admin</a>." +
                            $"<br /> " +
                            $"{ (NewKennel ? "<br />" + "Login Details: " : "") }" +
                            $"{ (NewKennel ? "<br />" + "Username: "******"") }" +
                            $"{ (NewKennel ? "<br />" + "Password: "******"") }" +
                            $"<br />" +
                            $"<br /> Kind Regards," +
                            $"<br /> <a href=\"{JsonSerializer.Deserialize<SystemConfiguration>(HttpContext.Session.GetString("SYSTEMCONFIGURATION")).WebsiteUrl}\">Bully Assure System</a>",
                            AttachmentsBinaries: null,
                            UserID: HttpContext.Session.GetString("UserID"),
                            systemConfiguration: JsonSerializer.Deserialize <SystemConfiguration>(HttpContext.Session.GetString("SYSTEMCONFIGURATION"))
                            );
                    }
                    else
                    {
                        emailHandler.SendEmail(
                            ToAddresses: new List <string> {
                            KennelDetails.EmailAddress
                        },
                            Subject: $"Bully Assure: Kennel Successfully Saved",
                            Body: $"Good Day <br />" +
                            $"<br /> " +
                            $"<br /> {KennelDetails.KennelName} has successfully been { (NewKennel ? "registered" : "saved") } on Bully Assure system." +
                            $"<br /> If you are not aware of this, please contact System Administrator on <a href=\"mailto:{JsonSerializer.Deserialize<SystemConfiguration>(HttpContext.Session.GetString("SYSTEMCONFIGURATION")).UserName}\">System Admin</a>." +
                            $"<br /> " +
                            $"<br />" +
                            $"<br /> Kind Regards," +
                            $"<br /> <a href=\"{JsonSerializer.Deserialize<SystemConfiguration>(HttpContext.Session.GetString("SYSTEMCONFIGURATION")).WebsiteUrl}\">Bully Assure System</a>",
                            AttachmentsBinaries: null,
                            UserID: HttpContext.Session.GetString("UserID"),
                            systemConfiguration: JsonSerializer.Deserialize <SystemConfiguration>(HttpContext.Session.GetString("SYSTEMCONFIGURATION"))
                            );
                    }

                    ViewData["Error"] = "Successfully saved kennel details.";
                }
                else
                {
                    ViewData["Error"] = "Failed to save kennel details.";
                }
                return(RedirectToAction("Index", "Kennel"));
            }
            catch (Exception ex)
            {
                LogFilter.Write(db, HttpContext.Request.QueryString.ToString(), HttpContext.Request.Path, HttpContext.Session.GetString("UserID"), ex);
                ViewData["Error"] = "Error Occurred";
                return(View("Error", ex));
            }
        }
        public async Task <IActionResult> Login([FromForm] string username, [FromForm] string password)
        {
            try
            {
                if (!string.IsNullOrEmpty(username) || !string.IsNullOrEmpty(password))
                {
                    var User = await this.db.Users.FirstOrDefaultAsync(e => e.Username == username && e.Password == new PasswordEncrypt().GeneratePassword(password) && !e.IsDeleted);

                    if (User == null)
                    {
                        LogAuditLogin LogLogin = new LogAuditLogin(db);
                        LogLogin.LogAudit(username, "Failed");

                        ViewData["Error"] = "Login Failed";
                        return(View("LoginPage"));
                    }
                    else
                    {
                        if (User.isKennel)
                        {
                            if (!await this.db.KennelUsers.Include(e => e.Kennel)
                                .AnyAsync(e => e.UserId == User.UserID &&
                                          e.Kennel.MembershipUpToDate &&
                                          !e.Kennel.isDeleted))
                            {
                                ViewData["Error"] = "Membership not up to date";
                                return(View("LoginPage"));
                            }
                        }
                        else if (User.isBreeder)
                        {
                            if (!await this.db.BreederUsers.Include(e => e.Breeder).ThenInclude(f => f.Kennel)
                                .AnyAsync(e => e.UserId == User.UserID &&
                                          e.Breeder.Kennel.MembershipUpToDate &&
                                          !e.Breeder.isDeleted &&
                                          !e.Breeder.Kennel.isDeleted))
                            {
                                ViewData["Error"] = "Membership not up to date";
                                return(View("LoginPage"));
                            }
                        }

                        LogAuditLogin LogLogin = new LogAuditLogin(db);
                        LogLogin.LogAudit(username, "Success");
                        var tokenString = GenerateJSONWebToken(User.UserID);

                        db.UserSessions.Update(new UserSession
                        {
                            EntryDate  = DateTime.Now,
                            ExpiryDate = DateTime.Now.AddHours(1),
                            Token      = tokenString,
                            UserMainID = User.UserID
                        });
                        db.SaveChanges();

                        HttpContext.Request.HttpContext.Session.Clear();
                        HttpContext.Session.SetString("UserID", User.UserID.ToString());
                        HttpContext.Session.SetString("token", tokenString);
                        HttpContext.Session.SetString("ExpiryDate", DateTime.Now.AddHours(1).ToString());

                        HttpContext.Session.SetString("SYSTEMCONFIGURATION", JsonSerializer.Serialize(db.SystemConfigurations.First() ?? throw new NullReferenceException("No System Configuration Defined.")));

                        ViewData["FirstName"] = User.Firstname;
                        ViewData["LastName"]  = User.Surname;

                        emailHandler.SendEmail(
                            ToAddresses: new List <string> {
                            User.Email
                        },
                            Subject: $"Bully Assure: Successful Login",
                            Body: $"Good Day <br />" +
                            $"<br /> " +
                            $"<br /> You successfully logged into Bully Assure system." +
                            $"<br /> If you are not aware of this, please contact System Administrator on <a href=\"mailto:{JsonSerializer.Deserialize<SystemConfiguration>(HttpContext.Session.GetString("SYSTEMCONFIGURATION")).UserName}\">System Admin</a>." +
                            $"<br /> " +
                            $"<br />" +
                            $"<br /> Kind Regards," +
                            $"<br /> <a href=\"{JsonSerializer.Deserialize<SystemConfiguration>(HttpContext.Session.GetString("SYSTEMCONFIGURATION")).WebsiteUrl}\">Bully Assure System</a>",
                            AttachmentsBinaries: null,
                            UserID: HttpContext.Session.GetString("UserID"),
                            systemConfiguration: JsonSerializer.Deserialize <SystemConfiguration>(HttpContext.Session.GetString("SYSTEMCONFIGURATION"))
                            );

                        return(RedirectToAction("Index", "Dashboard"));
                    }
                }
                else
                {
                    ViewData["Error"] = "No login details provided";
                    return(View("LoginPage"));
                }
            }
            catch (Exception ex)
            {
                LogFilter.Write(db, HttpContext.Request.QueryString.ToString(), HttpContext.Request.Path, HttpContext.Session.GetString("UserID"), ex);
                ViewData["Error"] = "Error Occurred";
                return(View("LoginPage"));
            }
        }