Example #1
0
        public int CompareTo(object obj)
        {
            if (obj == null)
            {
                return(1);
            }
            Admins item = obj as Admins;

            return(Email.CompareTo(item.Email));
        }
Example #2
0
        public static void Add(Admins Item, cap01devContext db)
        {
            try
            {
                if (db == null)
                {
                    throw new ApplicationException("Database connection not initialized");
                }
                Logger.Trace("Admins.Add IN");
                if (Item != null)
                {
                    Logger.Debug("Admins.Add userLogin: {0}", Item.Email);
                    Logger.Debug("Admins.Add fullName: {0}", Item.FullName);
                    Logger.Debug("Admins.Add comment: {0}", Item.Comment);
                }
                else
                {
                    Logger.Debug("Admins.Add Item==null");
                    return;
                }

                if (string.IsNullOrEmpty(Item.Email))
                {
                    throw new ValidationException("Missing required property: Email");
                }
                if (string.IsNullOrEmpty(Item.PasswordHash))
                {
                    throw new ValidationException("Missing required property: PasswordHash");
                }
                if (string.IsNullOrEmpty(Item.FullName))
                {
                    throw new ValidationException("Missing required property: FullName");
                }


                db.Admins.Add(Item);
                db.SaveChanges();
            }
            catch (ValidationException ex)
            {
                Logger.Error(ex, "Add new user to DB error");
                throw ex;
            }
            catch (Exception ex)
            {
                Logger.Error(ex, "Add new user to DB error");
                throw new Exception("Add new user to DB error", ex);
            }
            finally
            {
                Logger.Trace("Admins.Add OUT");
            }
        }
Example #3
0
 public static void Setpassword(string userLogin, string password)
 {
     try
     {
         Logger.Trace("Admins.Setpassword IN");
         Logger.Debug(string.Format("Admins.Setpassword userLogin: {0}", userLogin));
         using (cap01devContext db = new cap01devContext())
         {
             Admins item = GetUserByLogin(userLogin, db);
             if (item != null)
             {
                 Logger.Debug("User founded");
                 Logger.Debug("Admins.Setpassword user_id: {0}", item.Id);
                 item.Password = password;
                 db.SaveChanges();
             }
             else
             {
                 string mes = $"User {userLogin} not founded";
                 Logger.Debug(mes);
                 throw new KeyNotFoundException(mes);
             }
         }
     }
     catch (ValidationException ex)
     {
         Logger.Debug($"Update user error: {ex.Message}");
         throw ex;
     }
     catch (KeyNotFoundException ex)
     {
         Logger.Debug($"Update user error: {ex.Message}");
         throw ex;
     }
     catch (Exception ex)
     {
         Logger.Error(ex, "Update user error");
         throw new Exception("Update user error", ex);
     }
     finally
     {
         Logger.Trace("Admins.Setpassword OUT");
     }
 }
Example #4
0
        public static void AddOrUpdate(Admins Item, cap01devContext db)
        {
            try
            {
                Logger.Trace("Admins.Update IN");

                db.Update <Admins>(Item);
                db.SaveChanges();
            }
            catch (Exception ex)
            {
                Logger.Error(ex, "Update user error");
                throw new Exception("Update user error", ex);
            }
            finally
            {
                Logger.Trace("Admins.Delete OUT");
            }
        }
Example #5
0
        public static void Delete(string userLogin, cap01devContext db)
        {
            try
            {
                Logger.Trace("Admins.Delete IN");
                Logger.Debug("Admins.Delete userLogin: {0}", userLogin);
                Admins item = GetUserByLogin(userLogin, db);

                if (item != null)
                {
                    Logger.Debug("User founded");
                    Logger.Debug("Admins.Delete user_id: {0}", item.Id);
                    Logger.Debug("Admins.Delete User with user_id {0} and login {1} will be deleted", item.Id, item.Email);
                    db.Admins.Remove(item);
                    db.Remove <Admins>(item);
                    db.SaveChanges();
                    Logger.Debug("Admins.Del User deleted", item.Id, item.Email);
                }
                else
                {
                    string mes = $"User {userLogin} not founded";
                    Logger.Debug(mes);
                    throw new KeyNotFoundException(mes);
                }
            }
            catch (KeyNotFoundException ex)
            {
                throw ex;
            }
            catch (Exception ex)
            {
                Logger.Error(ex, "Delete user error");
                throw new Exception("Delete user error", ex);
            }
            finally
            {
                Logger.Trace("Admins.Delete OUT");
            }
        }
Example #6
0
 public static bool TestPassword(string userLogin, string password)
 {
     try
     {
         Logger.Trace("Admins.TestPassword IN");
         Logger.Debug("Admins.TestPassword userLogin: {0}", userLogin);
         using (cap01devContext db = new cap01devContext())
         {
             Admins item = GetUserByLogin(userLogin, db);
             if (item != null)
             {
                 Logger.Debug("User founded");
                 Logger.Debug("Admins.TestPassword user_id: {0}", item.Id);
                 bool result = item.TestPassword(password);
                 Logger.Debug("Admins.TestPassword result: {0}", result);
                 return(result);
             }
             else
             {
                 string mes = $"User {userLogin} not founded";
                 Logger.Debug(mes);
                 throw new KeyNotFoundException(mes);
             }
         }
     }
     catch (KeyNotFoundException ex)
     {
         throw ex;
     }
     catch (Exception ex)
     {
         Logger.Error(ex, "Test user password error");
         throw new Exception("Test user password error", ex);
     }
     finally
     {
         Logger.Trace("Admins.TestPassword OUT");
     }
 }
Example #7
0
        public static void Disable(string userLogin, cap01devContext db)
        {
            try
            {
                Logger.Trace("Admins.Disable IN");
                Logger.Debug("Admins.Disable userLogin: {0}", userLogin);

                Admins item = GetUserByLogin(userLogin, db);
                if (item != null)
                {
                    Logger.Debug("User founded");
                    Logger.Debug("Admins.Disable user_id: {0}", item.Id);
                    item.Disable();
                    db.Update <Admins>(item);
                    db.SaveChanges();
                }
                else
                {
                    Logger.Debug("User not founded");
                    throw new KeyNotFoundException("User not founded");
                }
            }
            catch (KeyNotFoundException ex)
            {
                Logger.Error(ex, $"User {userLogin} not exist");
                throw new KeyNotFoundException("Test user password error", ex);
            }
            catch (Exception ex)
            {
                Logger.Error(ex, "Disable user error");
                throw new Exception("Disable user error", ex);
            }
            finally
            {
                Logger.Trace("Admins.Disable OUT");
            }
        }
Example #8
0
 public static Admins Deserialize(Stream stream)
 {
     Logger.Trace("Admins.Deserialize() IN");
     if (stream == null)
     {
         return(null);
     }
     try
     {
         DataContractJsonSerializer serializer = new DataContractJsonSerializer(typeof(Admins));
         stream.Position = 0;
         Admins result = (Admins)serializer.ReadObject(stream);
         return(result);
     }
     catch (Exception ex)
     {
         Logger.Error(ex, "Admins deserialization error");
     }
     finally
     {
         Logger.Trace("Admins.Deserialize() OUT");
     }
     return(null);
 }
Example #9
0
 public bool Equals(Admins Item)
 {
     return(this.CompareTo(Item) == 0);
 }