public bool saveErrorInDB(ErrorRestViewModel err)
        {
            bool result = false;

            Error error1 = new Error()
            {
                errorDescription = err.errorDescription,
                logLevel         = err.logLevel,
                applicationID    = err.appID,
                exceptionMessage = err.exceptionMessage,
                timestamp        = err.timestamp.ToString()
            };

            using (ErrorLoggerDBContext context = new ErrorLoggerDBContext())
            {
                try
                {   //check if app ID exist - If App ID does not exist context.savechanges will fail and this will be catched in catch block.
                    context.Errors.Add(error1);
                    context.SaveChanges();
                    result = true;
                }
                catch (Exception ex)
                {
                    Log.Error("LoadersnLogic//SaveErrorinDB " + ex.Message);
                    throw ex;
                }
            }

            return(result);
        }
        public bool saveApplicationInDB(CreateApplicationViewModel app)
        {
            bool        result = false;
            Application app_   = new Application()
            {
                applicationName        = app.applicationName,
                applicationDescription = app.applicationDescription,
                applicationStatus      = app.applicationStatus.ToString()
            };

            using (ErrorLoggerDBContext context = new ErrorLoggerDBContext())
            {
                try
                {
                    var application = context.Applications.Where(x => x.applicationName.Equals(app.applicationName)).Any();
                    if (!application)
                    {
                        context.Applications.Add(app_);
                        context.SaveChanges();
                        result = true;
                    }
                }
                catch
                {
                    Log.Error("Function: saveApplicationInDB CustomizeDeveloperMessage: Not able to save Application in DB. Database Error.");
                    throw new Exception("CustomizeDeveloperMessage: Not able to save Application in DB. Database Error. ");
                }
            }

            return(result);
        }
        public bool updateApplicationInDB(ApplicationViewDetailMV app)
        {
            bool result = false;

            using (ErrorLoggerDBContext context = new ErrorLoggerDBContext())
            {
                try
                {
                    var application = from a in context.Applications
                                      where a.ApplicationId != app.applicationID
                                      select a;
                    foreach (Application a in application)
                    {
                        if (a.applicationName == app.applicationName)
                        {
                            return(false);
                        }
                    }
                    var app_ = context.Applications.Where(x => x.ApplicationId.Equals(app.applicationID)).First();
                    app_.applicationName        = app.applicationName;
                    app_.applicationStatus      = app.applicationStatus;
                    app_.applicationDescription = app.applicationDesc;
                    context.SaveChanges();
                    result = true;
                }
                catch
                {
                    Log.Error("Function: updateApplicationInDB CustomizeDeveloperMessage: Not able to update Application in DB. Database Error. ");
                    throw new Exception("CustomizeDeveloperMessage: Not able to update Application in DB. Database Error. ");
                }
            }

            return(result);
        }
Exemplo n.º 4
0
        public bool AddUser(RegisterUserViewModel newUser)
        {
            bool result = false;
            //hashing the password
            string hashedPassword = string.Empty;

            try
            {
                char[]   delim             = { '@' };
                string[] userNameAndDomain = newUser.Email.Split(delim);
                hashedPassword = Authentication.HashPassword(userNameAndDomain[0], newUser.Password);
            }
            catch
            {
                Log.Error("Function : AddUser CustomizeDeveloperMessage: Registration Failed due to server Error. Unable to hash given password.");
                throw new Exception("CustomizeDeveloperMessage: Registration Failed due to server Error. Unable to hash given password.");
            }

            Login login = new Login()
            {
                emailID  = newUser.Email,
                password = hashedPassword
            };
            User user = new User()
            {
                loginDetails = login,
                firstName    = newUser.FirstName,
                lastName     = newUser.LastName,
                roleID       = "User", //by Default User
                statusText   = newUser.Status.ToString()
            };

            using (ErrorLoggerDBContext context = new ErrorLoggerDBContext())
            {
                try
                {
                    if (!userData.Any(x => x.loginDetails.emailID == login.emailID))
                    {
                        context.Logins.Add(login);
                        context.Users.Add(user);
                        context.SaveChanges();
                        result = true;
                    }
                }
                catch
                {
                    Log.Error("Function: AddUser CustomizeDeveloperMessage: Registration Failed. Database Access Error. ");
                    throw new Exception("CustomizeDeveloperMessage: Registration Failed. Database Access Error.");
                }
            }

            return(result);
        }
Exemplo n.º 5
0
 public void updateLastLoginTimestamp(String emailID)
 {
     using (ErrorLoggerDBContext context = new ErrorLoggerDBContext())
     {
         try
         {
             var user = context.Users.Where(x => x.loginDetails.emailID.Equals(emailID)).First();
             user.lastLoginTimestamp = DateTime.Now.ToString();
             context.SaveChanges();
         }
         catch
         {
             Log.Error("Function: updateLastLoginTimestamp CustomizeDeveloperMessage: unable to update timestamp");
             throw new Exception("CustomizeDeveloperMessage: Login Failed. Database Error.");
         }
     }
 }
Exemplo n.º 6
0
        public bool updateUserInDB(EditUserMV user)
        {
            bool result = false;

            using (ErrorLoggerDBContext context = new ErrorLoggerDBContext())
            {
                try
                {
                    var user_ = context.Users.Include(x => x.loginDetails).Where(x => x.UserId != user.UserID).ToList();
                    foreach (User a in user_)
                    {
                        if (a.loginDetails.emailID == user.Email)
                        {
                            return(false);
                        }
                    }
                    var updateUser = context.Users.Where(x => x.UserId.Equals(user.UserID)).First();
                    updateUser.loginDetails.emailID = user.Email;
                    updateUser.firstName            = user.FirstName;
                    updateUser.lastName             = user.LastName;
                    updateUser.roleID     = user.Role;
                    updateUser.statusText = user.Status;
                    updateUser.Applications.Clear();
                    foreach (int appID in user.submittedApplications)
                    {
                        if (appID == -1)
                        {
                            break;
                        }
                        var application = context.Applications.Where(x => x.ApplicationId.Equals(appID)).First();
                        updateUser.Applications.Add(application);
                    }
                    context.SaveChanges();
                    result = true;
                }
                catch
                {
                    Log.Error("Function:updateUserInDB CustomizeDeveloperMessage: Not able to update Application in DB. Database Error.");
                    throw new Exception("CustomizeDeveloperMessage: Not able to update Application in DB. Database Error. ");
                }
            }

            return(result);
        }