Example #1
0
 /// <summary>
 /// Deletes the login with the given stringId
 /// </summary>
 /// <param name="stringId"></param>
 public int DeleteUser(string stringId)
 {
     try
     {
         var id = Int64.Parse(stringId);
         using (var db = new ReportAppLoginEntities())
         {
             db.Login.Remove(db.Login.FirstOrDefault(x => x.ID == id));
             db.SaveChanges();
         }
         return (int)codes.success;
     }
     catch (Exception e)
     {
         return (int)codes.fail;
     }
 }
Example #2
0
 /// <summary>
 /// Creates a login with the given parameters
 /// </summary>
 /// <param name="login"></param>
 public int CreateLogin(LoginDTO login)
 {
     try
     {
         using (var db = new ReportAppLoginEntities())
         {
             db.Login.Add(new Login()
             {
                 Username = login.Username,
                 Password = login.Password
             });
             db.SaveChanges();
         }
         return (int)codes.success;
     }
     catch (DbUpdateException e)
     {
         return (int)codes.user_exists;
     }
     catch (Exception e)
     {
         return (int)codes.fail;
     }
 }
Example #3
0
        /// <summary>
        /// Return the Login with the given username
        /// </summary>
        /// <param name="username"></param>
        /// <returns>A LoginDTO</returns>
        public LoginDTO GetUserByUsername(string username)
        {
            try
            {
                using (var db = new ReportAppLoginEntities())
                {

                    var login = db.Login.FirstOrDefault(x => x.Username.Equals(username));

                    if (login == null)
                    {
                        return new LoginDTO() { Code = (int)codes.no_user };
                    }

                    return new LoginDTO()
                    {
                        ID = login.ID,
                        Username = login.Username,
                        Password = login.Password,
                        Code = (int)codes.success
                    };
                }
            }
            catch (Exception e)
            {
                return new LoginDTO() { Code = -1 };
            }
        }