示例#1
0
        /// <summary>
        /// SendEmail method allows to persist an email to database with status (Sent Status) of false (Not sent)
        /// </summary>
        /// <param name="address">An email address to where an email is going to be sent</param>
        /// <param name="subject">An email subject</param>
        /// <param name="body">An email body (Main content)</param>
        public static void SendEmail(string address, string subject, string body)
        {
            try
            {
                using (SqlConnection sqlConnection = new SqlConnection(Global.connectionString))
                {
                    SqlCommand sqlCommand = new SqlCommand("SendEmail", sqlConnection);

                    sqlCommand.CommandType = CommandType.StoredProcedure;

                    sqlCommand.Parameters.AddWithValue("@Address", address);
                    sqlCommand.Parameters.AddWithValue("@Subject", subject);
                    sqlCommand.Parameters.AddWithValue("@Body", body);

                    sqlConnection.Open();

                    sqlCommand.ExecuteNonQuery();
                }
            }
            catch (SqlException ex)
            {
                // Log exception
                ErrorHandlingUtilities.LogException(ErrorHandlingUtilities.GetExceptionDetails(ex));
            }
        }
示例#2
0
        public IHttpActionResult PostNotificationByAdminUsername(string adminUsername, Notification notification)
        {
            if (ModelState.IsValid && !String.IsNullOrEmpty(adminUsername))
            {
                var admin = this.AdminService.GetOneAdminByUserName(adminUsername);

                notification.AdminId = admin.AdminId;

                this.NotificationService.CreateNotification(notification);

                try
                {
                    this.NotificationService.SaveChanges();
                }
                catch (DbUpdateException ex)
                {
                    // Log exception
                    ErrorHandlingUtilities.LogException(ErrorHandlingUtilities.GetExceptionDetails(ex));

                    return(Conflict());
                }

                return(CreatedAtRoute("DefaultApi", new { id = notification.NotificationId }, notification));
            }

            return(BadRequest(ModelState));
        }
示例#3
0
        public IHttpActionResult PostAgent(Agent agent)
        {
            if (ModelState.IsValid)
            {
                this.AgentService.CreateAgent(agent);

                try
                {
                    this.AgentService.SaveChanges();
                }
                catch (DbUpdateException ex)
                {
                    // Log exception
                    ErrorHandlingUtilities.LogException(ErrorHandlingUtilities.GetExceptionDetails(ex));

                    return(Conflict());
                }

                agent.Department = this.DepartmentService.GetOneDepartmentById(agent.DepartmentId);

                return(CreatedAtRoute("DefaultApi", new { id = agent.AgentId }, agent));
            }
            else
            {
                return(BadRequest(ModelState));
            }
        }
示例#4
0
        public IHttpActionResult PutCategory(Category category)
        {
            if (ModelState.IsValid)
            {
                this.CategoryService.UpdateCategory(category);

                try
                {
                    this.CategoryService.SaveChanges();

                    return(Ok(category));
                }
                catch (DbUpdateConcurrencyException ex)
                {
                    // Log exception
                    ErrorHandlingUtilities.LogException(ErrorHandlingUtilities.GetExceptionDetails(ex));

                    return(Conflict());
                }
                catch (DbUpdateException ex)
                {
                    // Log exception
                    ErrorHandlingUtilities.LogException(ErrorHandlingUtilities.GetExceptionDetails(ex));

                    if (!this.CategoryExists(category.CategoryId))
                    {
                        return(NotFound());
                    }

                    return(Conflict());
                }
            }

            return(BadRequest(ModelState));
        }
示例#5
0
        public async Task <PartialViewResult> PositionClosure(PositionClosureConfirmationViewModel model)
        {
            var positionResultViewModel = new PositionResultViewModel();

            var stringBuilder = new StringBuilder();

            if (ModelState.IsValid)
            {
                try
                {
                    var notification = Mapper.Map <NotificationAddViewModel, Notification>(new NotificationAddViewModel("Position Removal Request", String.Format("Position '{0}' ({1}) has been flagged for removal by client '{2}' ({3})", model.PositionTitle, model.PositionId.ToString("POS00000"), model.ClientFullName, model.ClientUserName), model.AgentId));

                    var response = await this.GetHttpClient().PostAsJsonAsync("Notification", notification); // Attempt to persist notification to the data context

                    if (response.IsSuccessStatusCode)
                    {
                        notification = await response.Content.ReadAsAsync <Notification>();

                        stringBuilder.Append("<div class='text-center'><h4><strong>Success!</strong></h4></div>");

                        stringBuilder.Append("<div class='row'><div class='col-md-12'><p></p></div><div class='col-md-offset-1 col-md-11'>Position closure request has been submitted successfully!</div>");

                        stringBuilder.Append("<div class='col-md-12'><p></p></div><div class='col-md-offset-1 col-md-11'><strong>NOTE:</strong> You will be notified when position closure is complete.</div></div>");

                        positionResultViewModel.Message = stringBuilder.ToString();

                        return(PartialView("_SuccessConfirmation", positionResultViewModel));
                    }
                    else
                    {
                        throw new NotificationAddException(String.Format("Notification could NOT be added. Status Code: {1}", response.StatusCode));
                    }
                }
                catch (NotificationAddException ex)
                {
                    // Log exception
                    ErrorHandlingUtilities.LogException(ErrorHandlingUtilities.GetExceptionDetails(ex));

                    stringBuilder.Append("<div class='text-center'><h4><strong>Failed to create new notification.</strong></h4></div>");

                    stringBuilder.Append("<div class='row'><div class='col-md-12'><p></p></div><div class='col-md-offset-1 col-md-11'>An exception has been thrown while attempting to create new notification.</div>");

                    stringBuilder.Append("<div class='col-md-12'><p></p></div><div class='col-md-offset-1 col-md-11'><strong>NOTE:</strong> Please review an exception log for more information about the exception.</div></div>");

                    positionResultViewModel.Message = stringBuilder.ToString();

                    return(PartialView("_FailureConfirmation", positionResultViewModel));
                }
            }

            stringBuilder.Append("<div class='text-center'><h4><strong>Failed to send a close request!</strong></h4></div>");

            stringBuilder.Append("<div class='text-center'>Position closure request could not be subitted at this time.</div>");

            stringBuilder.Append("<div class='text-center'><strong>NOTE:</strong> If you encounter this issue again in the future, please contact Technical Support with exact steps to reproduce this issue.</div>");

            positionResultViewModel.Message = stringBuilder.ToString();

            return(PartialView("_FailureConfirmation", positionResultViewModel));
        }
示例#6
0
        public async Task <PartialViewResult> ForgotPassword(ForgotPasswordViewModel model)
        {
            if (!String.IsNullOrEmpty(model.UserName) && !String.IsNullOrEmpty(model.Email))
            {
                var user = await this.GetUserManager.FindByNameAsync(model.UserName);

                if (user != null)                  // Check if user exists
                {
                    if (user.Email != model.Email) // Check if user name matches with email
                    {
                        ModelState.AddModelError("", "User name or email address does not match our records. Please try again.");
                    }
                }
                else
                {
                    ModelState.AddModelError("", "User name or email address does not match our records. Please try again.");
                }
            }

            if (ModelState.IsValid)
            {
                try
                {
                    var template = HttpContext.Server.MapPath("~/App_Data/UserPasswordResetEmailTemplate.txt");

                    var message = System.IO.File.ReadAllText(template);

                    message = message.Replace("%username%", model.UserName).Replace("%email%", model.Email);

                    // TODO - Change "*****@*****.**" to the email address of admin group
                    Email.EmailService.SendEmail("*****@*****.**", "Request to reset user password.", message); // Send a request to reset user password to admin group email address
                }
                catch (System.IO.FileNotFoundException ex)
                {
                    // Log exception
                    ErrorHandlingUtilities.LogException(ErrorHandlingUtilities.GetExceptionDetails(ex));
                }
                catch (System.IO.IOException ex)
                {
                    // Log exception
                    ErrorHandlingUtilities.LogException(ErrorHandlingUtilities.GetExceptionDetails(ex));
                }

                var stringBuilder = new StringBuilder();

                stringBuilder.Append("<div class='text-center'><h4><strong>Success!</strong></h4></div>");

                stringBuilder.Append("<div class='row'><div class='col-md-12'><p></p></div><div class='col-md-offset-1 col-md-11'>Request to reset user password has been sent to the RAMS Administration.</div>");

                stringBuilder.Append("<div class='col-md-12'><p></p></div><div class='col-md-offset-1 col-md-11'>You will receive your new login credentials by an email once request is complete.</div>");

                stringBuilder.Append("<div class='col-md-12'><p></p></div><div class='col-md-offset-1 col-md-11'><strong>NOTE: </strong> Please remember NOT to share your login credentials with anyone.</div></div>");

                var userConfirmationViewModel = new UserConfirmationViewModel(stringBuilder.ToString());

                return(PartialView("_ForgotPasswordConfirmation", userConfirmationViewModel));
            }

            return(PartialView("_ForgotPassword", model));
        }
示例#7
0
        public IHttpActionResult DeleteNotification(int id)
        {
            if (id > 0)
            {
                var notification = this.NotificationService.GetOneNotificationById(id);

                if (notification != null)
                {
                    this.NotificationService.DeleteNotification(notification);

                    try
                    {
                        this.NotificationService.SaveChanges();
                    }
                    catch (DbUpdateException ex)
                    {
                        // Log exception
                        ErrorHandlingUtilities.LogException(ErrorHandlingUtilities.GetExceptionDetails(ex));

                        if (!this.NotificationExists(notification.NotificationId))
                        {
                            return(NotFound());
                        }

                        return(Conflict());
                    }

                    return(Ok(notification));
                }
            }

            return(NotFound());
        }
示例#8
0
        public IHttpActionResult PutDepartment(Department department)
        {
            if (ModelState.IsValid)
            {
                this.DepartmentService.UpdateDepartment(department);

                try
                {
                    this.DepartmentService.SaveChanges();

                    return(Ok(department));
                }
                catch (DbUpdateConcurrencyException ex)
                {
                    // Log exception
                    ErrorHandlingUtilities.LogException(ErrorHandlingUtilities.GetExceptionDetails(ex));

                    return(Conflict());
                }
                catch (DbUpdateException ex)
                {
                    // Log exception
                    ErrorHandlingUtilities.LogException(ErrorHandlingUtilities.GetExceptionDetails(ex));

                    if (!this.DepartmentExists(department.DepartmentId))
                    {
                        return(NotFound());
                    }

                    return(Conflict());
                }
            }

            return(BadRequest(ModelState));
        }
示例#9
0
        public IHttpActionResult DeleteDepartment(int id)
        {
            if (id > 0)
            {
                var department = this.DepartmentService.GetOneDepartmentById(id);

                if (department != null)
                {
                    this.DepartmentService.DeleteDepartment(department);

                    try
                    {
                        this.DepartmentService.SaveChanges();
                    }
                    catch (DbUpdateException ex)
                    {
                        // Log exception
                        ErrorHandlingUtilities.LogException(ErrorHandlingUtilities.GetExceptionDetails(ex));

                        if (!this.DepartmentExists(department.DepartmentId))
                        {
                            return(NotFound());
                        }

                        return(Conflict());
                    }

                    return(Ok(department));
                }
            }

            return(NotFound());
        }
示例#10
0
        public IHttpActionResult PutNotification(Notification notification)
        {
            if (ModelState.IsValid)
            {
                this.NotificationService.UpdateNotification(notification);

                try
                {
                    this.NotificationService.SaveChanges();

                    return(Ok(notification));
                }
                catch (DbUpdateConcurrencyException ex)
                {
                    // Log exception
                    ErrorHandlingUtilities.LogException(ErrorHandlingUtilities.GetExceptionDetails(ex));

                    return(Conflict());
                }
                catch (DbUpdateException ex)
                {
                    // Log exception
                    ErrorHandlingUtilities.LogException(ErrorHandlingUtilities.GetExceptionDetails(ex));

                    if (!this.NotificationExists(notification.NotificationId))
                    {
                        return(NotFound());
                    }

                    return(Conflict());
                }
            }

            return(BadRequest(ModelState));
        }
示例#11
0
        public IHttpActionResult DeleteInterview(int id)
        {
            if (id > 0)
            {
                var interview = this.InterviewService.GetOneInterviewById(id);

                if (interview != null)
                {
                    this.InterviewService.DeleteInterview(interview);

                    try
                    {
                        this.InterviewService.SaveChanges();
                    }
                    catch (DbUpdateException ex)
                    {
                        // Log exception
                        ErrorHandlingUtilities.LogException(ErrorHandlingUtilities.GetExceptionDetails(ex));

                        if (!this.InterviewExists(interview.InterviewId))
                        {
                            return(NotFound());
                        }

                        return(Conflict());
                    }

                    return(Ok(interview));
                }
            }

            return(NotFound());
        }
示例#12
0
        public IHttpActionResult PutInterview(Interview interview)
        {
            if (ModelState.IsValid)
            {
                this.InterviewService.UpdateInterview(interview);

                try
                {
                    this.InterviewService.SaveChanges();

                    return(Ok(interview));
                }
                catch (DbUpdateConcurrencyException ex)
                {
                    // Log exception
                    ErrorHandlingUtilities.LogException(ErrorHandlingUtilities.GetExceptionDetails(ex));

                    return(Conflict());
                }
                catch (DbUpdateException ex)
                {
                    // Log exception
                    ErrorHandlingUtilities.LogException(ErrorHandlingUtilities.GetExceptionDetails(ex));

                    if (!this.InterviewExists(interview.InterviewId))
                    {
                        return(NotFound());
                    }

                    return(Conflict());
                }
            }

            return(BadRequest(ModelState));
        }
示例#13
0
        public IHttpActionResult DeleteCategory(int id)
        {
            if (id > 0)
            {
                var category = this.CategoryService.GetOneCategoryById(id);

                if (category != null)
                {
                    this.CategoryService.DeleteCategory(category);

                    try
                    {
                        this.CategoryService.SaveChanges();
                    }
                    catch (DbUpdateException ex)
                    {
                        // Log exception
                        ErrorHandlingUtilities.LogException(ErrorHandlingUtilities.GetExceptionDetails(ex));

                        if (!this.CategoryExists(category.CategoryId))
                        {
                            return(NotFound());
                        }

                        return(Conflict());
                    }

                    return(Ok(category));
                }
            }

            return(NotFound());
        }
示例#14
0
        public IHttpActionResult DeletePosition([FromUri] Int32[] positionIds)
        {
            if (positionIds.Length > 0)
            {
                try
                {
                    for (int i = 0; i < positionIds.Length; i++)
                    {
                        var position = this.PositionService.GetOnePositionById(positionIds[i]);

                        if (position != null)
                        {
                            this.PositionArchiveService.CreateArchivePosition(Mapper.Map <Position, PositionArchive>(position));

                            if (!Utilities.IsEmpty(position.Candidates))
                            {
                                foreach (var candidate in position.Candidates.ToList())
                                {
                                    this.CandidateArchiveService.CreateCandidateArchive(Mapper.Map <Candidate, CandidateArchive>(candidate));


                                    if (!Utilities.IsEmpty(candidate.Interviews))
                                    {
                                        foreach (var interview in candidate.Interviews.ToList())
                                        {
                                            this.InterviewService.DeleteInterview(interview);

                                            this.InterviewService.SaveChanges();
                                        }
                                    }

                                    this.CandidateService.DeleteCandidate(candidate);
                                }
                            }

                            this.PositionService.DeletePosition(position);
                        }
                    }

                    this.PositionService.SaveChanges();
                    this.CandidateService.SaveChanges();
                    this.PositionArchiveService.SaveChanges();
                    this.CandidateArchiveService.SaveChanges();
                }
                catch (DbUpdateException ex)
                {
                    // Log exception
                    ErrorHandlingUtilities.LogException(ErrorHandlingUtilities.GetExceptionDetails(ex));

                    return(Conflict());
                }

                return(Ok());
            }

            return(NotFound());
        }
示例#15
0
        public IHttpActionResult AssignPosition(int positionId, int agentId)
        {
            if (positionId > 0)
            {
                var position = this.PositionService.GetOnePositionById(positionId);

                if (position != null)
                {
                    if (agentId == position.AgentId)
                    {
                        return(Ok(position));
                    }

                    if (agentId != 0)
                    {
                        position.AgentId = agentId;
                    }
                    else
                    {
                        position.AgentId = null;
                    }

                    this.PositionService.UpdatePosition(position);

                    try
                    {
                        this.PositionService.SaveChanges();
                    }
                    catch (DbUpdateConcurrencyException ex)
                    {
                        // Log exception
                        ErrorHandlingUtilities.LogException(ErrorHandlingUtilities.GetExceptionDetails(ex));

                        return(Conflict());
                    }
                    catch (DbUpdateException ex)
                    {
                        // Log exception
                        ErrorHandlingUtilities.LogException(ErrorHandlingUtilities.GetExceptionDetails(ex));

                        if (!this.PositionExists(position.PositionId))
                        {
                            return(NotFound());
                        }

                        return(Conflict());
                    }

                    position.Agent = this.AgentService.GetOneAgentById((int)position.AgentId);

                    return(Ok(position));
                }
            }

            return(NotFound());
        }
示例#16
0
        public IHttpActionResult ChangeNotificationStatus(int id, bool isReadStatus = false)
        {
            if (id > 0)
            {
                var notification = this.NotificationService.GetOneNotificationById(id);

                if (notification != null)
                {
                    if (isReadStatus)
                    {
                        if (notification.Status != Enums.NotificationStatus.Read)
                        {
                            notification.Status = Enums.NotificationStatus.Read;
                        }
                    }
                    else
                    {
                        if (notification.Status != Enums.NotificationStatus.Unread)
                        {
                            notification.Status = Enums.NotificationStatus.Unread;
                        }
                    }

                    this.NotificationService.UpdateNotification(notification);

                    try
                    {
                        this.NotificationService.SaveChanges();
                    }
                    catch (DbUpdateConcurrencyException ex)
                    {
                        // Log exception
                        ErrorHandlingUtilities.LogException(ErrorHandlingUtilities.GetExceptionDetails(ex));

                        return(Conflict());
                    }
                    catch (DbUpdateException ex)
                    {
                        // Log exception
                        ErrorHandlingUtilities.LogException(ErrorHandlingUtilities.GetExceptionDetails(ex));

                        if (!this.NotificationExists(notification.NotificationId))
                        {
                            return(NotFound());
                        }

                        return(Conflict());
                    }

                    return(Ok(notification));
                }
            }

            return(NotFound());
        }
示例#17
0
        public IHttpActionResult UpdateCandidateFeedback(int candidateId, string feedback, bool isInterviewed)
        {
            if (candidateId > 0)
            {
                var candidate = this.CandidateService.GetOneCandidateById(candidateId);

                if (candidate != null)
                {
                    if (feedback != candidate.Feedback)
                    {
                        candidate.Feedback = feedback;
                    }

                    if (isInterviewed)
                    {
                        candidate.Status = Enums.CandidateStatus.Interviewed;

                        var interview = this.InterviewService.GetOneInterviewById(candidate.Interviews.FirstOrDefault().InterviewId);

                        interview.Status = Enums.InterviewStatus.Complete;
                    }

                    this.CandidateService.UpdateCandidate(candidate);

                    try
                    {
                        this.CandidateService.SaveChanges();
                        this.InterviewService.SaveChanges();
                    }
                    catch (DbUpdateConcurrencyException ex)
                    {
                        // Log exception
                        ErrorHandlingUtilities.LogException(ErrorHandlingUtilities.GetExceptionDetails(ex));

                        return(Conflict());
                    }
                    catch (DbUpdateException ex)
                    {
                        // Log exception
                        ErrorHandlingUtilities.LogException(ErrorHandlingUtilities.GetExceptionDetails(ex));

                        if (!this.CandidateExists(candidate.CandidateId))
                        {
                            return(NotFound());
                        }

                        return(Conflict());
                    }

                    return(Ok(candidate));
                }
            }

            return(NotFound());
        }
示例#18
0
        public IHttpActionResult UpdatePositionStatus(int positionId, int status)
        {
            if (positionId > 0)
            {
                var position = this.PositionService.GetOnePositionById(positionId);

                if (position != null)
                {
                    if (status == (int)position.Status)
                    {
                        return(Ok(position));
                    }

                    position.Status = (PositionStatus)status;

                    if ((PositionStatus)status == PositionStatus.Closed)
                    {
                        position.CloseDate = DateTime.Now;
                    }

                    this.PositionService.UpdatePosition(position);

                    try
                    {
                        this.PositionService.SaveChanges();
                    }
                    catch (DbUpdateConcurrencyException ex)
                    {
                        // Log exception
                        ErrorHandlingUtilities.LogException(ErrorHandlingUtilities.GetExceptionDetails(ex));

                        return(Conflict());
                    }
                    catch (DbUpdateException ex)
                    {
                        // Log exception
                        ErrorHandlingUtilities.LogException(ErrorHandlingUtilities.GetExceptionDetails(ex));

                        if (!this.PositionExists(position.PositionId))
                        {
                            return(NotFound());
                        }

                        return(Conflict());
                    }

                    return(Ok(position));
                }
            }

            return(NotFound());
        }
示例#19
0
        public IHttpActionResult CreateInterview(int candidateId, string selectedDate, string agentUserName, bool selected)
        {
            if (candidateId > 0 && !String.IsNullOrEmpty(selectedDate) && !String.IsNullOrEmpty(agentUserName))
            {
                if (selected)
                {
                    var interviews = this.InterviewService.GetManyInterviewsByCandidateId(candidateId);

                    if (!Utilities.IsEmpty(interviews))
                    {
                        foreach (var item in interviews.ToList())
                        {
                            this.DeleteInterview(item.InterviewId);
                        }
                    }
                }

                var interview = new Interview();

                interview.CandidateId   = candidateId;
                interview.InterviewDate = Convert.ToDateTime(selectedDate);
                interview.InterviewerId = this.AgentService.GetOneAgentByUserName(agentUserName).AgentId;
                interview.Status        = Enums.InterviewStatus.Scheduled;

                this.InterviewService.CreateInterview(interview);

                var candidate = this.CandidateService.GetOneCandidateById(candidateId);

                candidate.Status = Enums.CandidateStatus.Pending;

                this.CandidateService.UpdateCandidate(candidate);

                try
                {
                    this.InterviewService.SaveChanges();
                    this.CandidateService.SaveChanges();
                }
                catch (DbUpdateException ex)
                {
                    // Log exception
                    ErrorHandlingUtilities.LogException(ErrorHandlingUtilities.GetExceptionDetails(ex));

                    return(Conflict());
                }

                interview.Candidate = this.CandidateService.GetOneCandidateById(candidateId);

                return(CreatedAtRoute("DefaultApi", new { id = interview.InterviewId }, interview));
            }

            return(BadRequest());
        }
示例#20
0
        public IHttpActionResult DeleteClientByUserName(string userName, bool physicalDelete = false)
        {
            if (!String.IsNullOrEmpty(userName))
            {
                var client = this.ClientService.GetOneClientByUserName(userName);

                if (client != null)
                {
                    if (physicalDelete)
                    {
                        this.ClientService.DeleteClient(client);
                    }
                    else
                    {
                        client.UserStatus = Enums.UserStatus.Deleted;

                        this.ClientService.UpdateClient(client);
                    }

                    try
                    {
                        this.ClientService.SaveChanges();

                        if (client.UserStatus != Enums.UserStatus.Deleted)
                        {
                            client.UserStatus = Enums.UserStatus.Deleted;
                        }
                    }
                    catch (DbUpdateException ex)
                    {
                        // Log exception
                        ErrorHandlingUtilities.LogException(ErrorHandlingUtilities.GetExceptionDetails(ex));

                        if (!this.ClientExists(client.ClientId))
                        {
                            return(NotFound());
                        }

                        return(Conflict());
                    }

                    return(Ok(client));
                }
            }

            return(NotFound());
        }
示例#21
0
        public IHttpActionResult DeleteAgentById(int id, bool physicalDelete = false)
        {
            if (id > 0)
            {
                var agent = this.AgentService.GetOneAgentById(id);

                if (agent != null)
                {
                    if (physicalDelete)
                    {
                        this.AgentService.DeleteAgent(agent);
                    }
                    else
                    {
                        agent.UserStatus = Enums.UserStatus.Deleted;

                        this.AgentService.UpdateAgent(agent);
                    }

                    try
                    {
                        this.AgentService.SaveChanges();

                        if (agent.UserStatus != Enums.UserStatus.Deleted)
                        {
                            agent.UserStatus = Enums.UserStatus.Deleted;
                        }
                    }
                    catch (DbUpdateException ex)
                    {
                        // Log exception
                        ErrorHandlingUtilities.LogException(ErrorHandlingUtilities.GetExceptionDetails(ex));

                        if (!this.AgentExists(agent.AgentId))
                        {
                            return(NotFound());
                        }

                        return(Conflict());
                    }

                    return(Ok(agent));
                }
            }

            return(NotFound());
        }
示例#22
0
        public IHttpActionResult DeleteAdminByUserName(string userName, bool physicalDelete = false)
        {
            if (!String.IsNullOrEmpty(userName))
            {
                var admin = this.AdminService.GetOneAdminByUserName(userName);

                if (admin != null)
                {
                    if (physicalDelete)
                    {
                        this.AdminService.DeleteAdmin(admin);
                    }
                    else
                    {
                        admin.UserStatus = Enums.UserStatus.Deleted;

                        this.AdminService.UpdateAdmin(admin);
                    }

                    try
                    {
                        this.AdminService.SaveChanges();

                        if (admin.UserStatus != Enums.UserStatus.Deleted)
                        {
                            admin.UserStatus = Enums.UserStatus.Deleted;
                        }
                    }
                    catch (DbUpdateException ex)
                    {
                        // Log exception
                        ErrorHandlingUtilities.LogException(ErrorHandlingUtilities.GetExceptionDetails(ex));

                        if (!this.AdminExists(admin.AdminId))
                        {
                            return(NotFound());
                        }

                        return(Conflict());
                    }

                    return(Ok(admin));
                }
            }

            return(NotFound());
        }
示例#23
0
        public ActionResult DeleteProfilePicture()
        {
            var success = false;

            try
            {
                if (System.IO.File.Exists(System.IO.Path.Combine(Server.MapPath("~/Content/ProfilePictures/"), User.Identity.Name + ".jpg")))
                {
                    System.IO.File.Delete(System.IO.Path.Combine(Server.MapPath("~/Content/ProfilePictures/"), User.Identity.Name + ".jpg")); // Delete .jpg file if it exists

                    success = true;
                }

                if (System.IO.File.Exists(System.IO.Path.Combine(Server.MapPath("~/Content/ProfilePictures/"), User.Identity.Name + ".png")))
                {
                    System.IO.File.Delete(System.IO.Path.Combine(Server.MapPath("~/Content/ProfilePictures/"), User.Identity.Name + ".png")); // Delete .png file if it exists

                    success = true;
                }

                if (System.IO.File.Exists(System.IO.Path.Combine(Server.MapPath("~/Content/ProfilePictures/"), User.Identity.Name + ".gif")))
                {
                    System.IO.File.Delete(System.IO.Path.Combine(Server.MapPath("~/Content/ProfilePictures/"), User.Identity.Name + ".gif")); // Delete .gif file if it exists

                    success = true;
                }

                if (success)
                {
                    return(RedirectToAction("Index", "Profile", new { Area = "SystemAdmin", message = "Profile picture has been successfully deleted." }));
                }

                return(RedirectToAction("Index", "Profile", new { Area = "SystemAdmin", message = "Profile picture could NOT be deleted at this time." }));
            }
            catch (System.IO.IOException ex)
            {
                // Log exception
                ErrorHandlingUtilities.LogException(ErrorHandlingUtilities.GetExceptionDetails(ex));

                return(RedirectToAction("Index", "Profile", new { Area = "SystemAdmin", message = "An exception has occured. Please review exception log for more details." }));
            }
        }
示例#24
0
        }                                                             // Database setter and getter for CandidateArchive class

        /// <summary>
        /// Commit method allows to commit changes to database (Without commit, changes will NOT be persisted to database)
        /// </summary>
        public virtual void Commit()
        {
            try
            {
                base.SaveChanges();
            }
            #pragma warning disable 0168 // Supressing warning 0168 "The variable 'ex' is declared but never used"
            catch (DbUpdateConcurrencyException ex)
            #pragma warning restore 0168
            {
                throw;
            }
            #pragma warning disable 0168 // Supressing warning 0168 "The variable 'ex' is declared but never used"
            catch (DbUpdateException ex)
            #pragma warning restore 0168
            {
                throw;
            }
            catch (DbEntityValidationException ex)
            {
                // Extract properties and related errors and log them
                var exceptionInfo = "";

                if (!Utilities.IsEmpty(ex.EntityValidationErrors))
                {
                    foreach (var errors in ex.EntityValidationErrors)
                    {
                        if (!Utilities.IsEmpty(errors.ValidationErrors))
                        {
                            foreach (var error in errors.ValidationErrors)
                            {
                                exceptionInfo += String.Format("Property: {0} Error: {1}" + Environment.NewLine, error.PropertyName, error.ErrorMessage);
                            }
                        }
                    }
                }

                // Log exception
                ErrorHandlingUtilities.LogException(ex.ToString(), null, null, exceptionInfo);
            }
        }
示例#25
0
        public IHttpActionResult PostCategory(Category category)
        {
            if (ModelState.IsValid)
            {
                this.CategoryService.CreateCategory(category);

                try
                {
                    this.CategoryService.SaveChanges();
                }
                catch (DbUpdateException ex)
                {
                    // Log exception
                    ErrorHandlingUtilities.LogException(ErrorHandlingUtilities.GetExceptionDetails(ex));

                    return(Conflict());
                }

                return(CreatedAtRoute("DefaultApi", new { id = category.CategoryId }, category));
            }

            return(BadRequest(ModelState));
        }
示例#26
0
        public IHttpActionResult PostInterview(Interview interview)
        {
            if (ModelState.IsValid)
            {
                this.InterviewService.CreateInterview(interview);

                try
                {
                    this.InterviewService.SaveChanges();
                }
                catch (DbUpdateException ex)
                {
                    // Log exception
                    ErrorHandlingUtilities.LogException(ErrorHandlingUtilities.GetExceptionDetails(ex));

                    return(Conflict());
                }

                return(CreatedAtRoute("DefaultApi", new { id = interview.InterviewId }, interview));
            }

            return(BadRequest(ModelState));
        }
示例#27
0
        public IHttpActionResult PostDepartment(Department department)
        {
            if (ModelState.IsValid)
            {
                this.DepartmentService.CreateDepartment(department);

                try
                {
                    this.DepartmentService.SaveChanges();
                }
                catch (DbUpdateException ex)
                {
                    // Log exception
                    ErrorHandlingUtilities.LogException(ErrorHandlingUtilities.GetExceptionDetails(ex));

                    return(Conflict());
                }

                return(CreatedAtRoute("DefaultApi", new { id = department.DepartmentId }, department));
            }

            return(BadRequest(ModelState));
        }
示例#28
0
        public IHttpActionResult PostNotification(Notification notification)
        {
            if (ModelState.IsValid)
            {
                this.NotificationService.CreateNotification(notification);

                try
                {
                    this.NotificationService.SaveChanges();
                }
                catch (DbUpdateException ex)
                {
                    // Log exception
                    ErrorHandlingUtilities.LogException(ErrorHandlingUtilities.GetExceptionDetails(ex));

                    return(Conflict());
                }

                return(CreatedAtRoute("DefaultApi", new { id = notification.NotificationId }, notification));
            }

            return(BadRequest(ModelState));
        }
示例#29
0
        public async Task <PartialViewResult> ChangePassword(ChangePasswordViewModel model)
        {
            var stringBuilder = new StringBuilder();

            var userConfirmationViewModel = new UserConfirmationViewModel();

            var identity = new ApplicationUser();

            // If any of password fields is empty, display _Error partial view with following error message "Not all required fields were entered."
            if (String.IsNullOrEmpty(model.CurrentPassword) || String.IsNullOrEmpty(model.Password) || String.IsNullOrEmpty(model.ConfirmPassword))
            {
                stringBuilder.Append("<div class='text-center'><h4><strong>Password could NOT be changed.</strong></h4></div>");

                stringBuilder.Append("<div class='row'><div class='col-md-12'><p></p></div><div class='col-md-offset-1 col-md-11'>Not all required fields were entered.</div>");

                stringBuilder.Append("<div class='col-md-12'><p></p></div><div class='col-md-offset-1 col-md-11'>Please ensure that all required fields are entered.</div></div>");

                userConfirmationViewModel = new UserConfirmationViewModel(stringBuilder.ToString());

                return(PartialView("_FailureConfirmation", userConfirmationViewModel));
            }

            if (!String.IsNullOrEmpty(model.CurrentPassword))
            {
                // If current password does not match database records, display _Error partial view with following error message "Current Password does NOT match our records."
                if ((identity = this.GetUserManager.Find(model.UserName, model.CurrentPassword)) == null)
                {
                    stringBuilder.Append("<div class='text-center'><h4><strong>Password could NOT be changed.</strong></h4></div>");

                    stringBuilder.Append("<div class='row'><div class='col-md-12'><p></p></div><div class='col-md-offset-1 col-md-11'>Current Password does NOT match our records.</div>");

                    stringBuilder.Append("<div class='col-md-12'><p></p></div><div class='col-md-offset-1 col-md-11'>Please try again using valid password.</div></div>");

                    userConfirmationViewModel = new UserConfirmationViewModel(stringBuilder.ToString());

                    return(PartialView("_FailureConfirmation", userConfirmationViewModel));
                }
            }

            if (!String.IsNullOrEmpty(model.Password))
            {
                // If password has less than 6 characters, display _Error partial view with following error message "Passwords must be at least 6 character long and up to 100 characters long."
                if (model.Password.Length < 6)
                {
                    stringBuilder.Append("<div class='text-center'><h4><strong>Password could NOT be changed.</strong></h4></div>");

                    stringBuilder.Append("<div class='row'><div class='col-md-12'><p></p></div><div class='col-md-offset-1 col-md-11'>Passwords must be at least 6 character long and up to 100 characters long.</div>");

                    stringBuilder.Append("<div class='col-md-12'><p></p></div><div class='col-md-offset-1 col-md-11'>Please try again using valid password pattern.</div></div>");

                    userConfirmationViewModel = new UserConfirmationViewModel(stringBuilder.ToString());

                    return(PartialView("_FailureConfirmation", userConfirmationViewModel));
                }
                // If password is invalid format, display _Error partial view with following error message "Passwords must have at least one non letter or digit character, least one lowercase ('a'-'z'), least one uppercase ('A'-'Z')."
                else if (!Utilities.RegexMatch(this.PasswordRegex, model.Password))
                {
                    stringBuilder.Append("<div class='text-center'><h4><strong>Password could NOT be changed.</strong></h4></div>");

                    stringBuilder.Append("<div class='row'><div class='col-md-12'><p></p></div><div class='col-md-offset-1 col-md-11'>New Passwords must have at least one non letter or digit character, least one lowercase ('a'-'z'), least one uppercase ('A'-'Z').</div>");

                    stringBuilder.Append("<div class='col-md-12'><p></p></div><div class='col-md-offset-1 col-md-11'>Please try again using valid password pattern.</div></div>");

                    userConfirmationViewModel = new UserConfirmationViewModel(stringBuilder.ToString());

                    return(PartialView("_FailureConfirmation", userConfirmationViewModel));
                }
            }

            if (ModelState.IsValid)
            {
                if (identity != null)
                {
                    // Attempt to change password
                    try
                    {
                        var result = await this.GetUserManager.ChangePasswordAsync(identity.Id, model.CurrentPassword, model.Password);

                        if (!result.Succeeded)
                        {
                            var message = String.Format("Password could not be changed from user {0}.", identity.UserName);

                            if (!Utilities.IsEmpty(result.Errors))
                            {
                                foreach (var error in result.Errors)
                                {
                                    message += " " + error;
                                }
                            }

                            throw new PasswordChangeException(message);
                        }

                        stringBuilder.Append("<div class='text-center'><h4><strong>Success!</strong></h4></div>");

                        stringBuilder.Append("<div class='row'><div class='col-md-12'><p></p></div><div class='col-md-offset-1 col-md-11'>User password has been successfully changed.</div>");

                        stringBuilder.Append("<div class='col-md-12'><p></p></div><div class='col-md-offset-1 col-md-11'>Please remember NOT to share your login credentials with anyone.</div></div>");

                        userConfirmationViewModel = new UserConfirmationViewModel(stringBuilder.ToString());

                        return(PartialView("_SuccessConfirmation", userConfirmationViewModel));
                    }
                    catch (PasswordChangeException ex)
                    {
                        // Log exception
                        ErrorHandlingUtilities.LogException(ErrorHandlingUtilities.GetExceptionDetails(ex));

                        stringBuilder.Append("<div class='text-center'><h4><strong>Password could NOT be changed.</strong></h4></div>");

                        stringBuilder.Append("<div class='row'><div class='col-md-12'><p></p></div><div class='col-md-offset-1 col-md-11'>An exception has been caught while attempting to change a user password. Please review an exception log for more details about the exception.</div></div>");

                        userConfirmationViewModel = new UserConfirmationViewModel(stringBuilder.ToString());

                        return(PartialView("_FailureConfirmation", userConfirmationViewModel));
                    }
                }
            }

            stringBuilder.Append("<div class='text-center'><h4><strong>Password could NOT be changed.</strong></h4></div>");

            stringBuilder.Append("<div class='row'><div class='col-md-12'><p></p></div><div class='col-md-offset-1 col-md-11'>ModelState is not valid for current instance of the request. Please try again in a moment.</div>");

            stringBuilder.Append("<div class='col-md-12'><p></p></div><div class='col-md-offset-1 col-md-11'><strong>NOTE:</strong> If you encounter this issue again in the future, please contact Technical Support with exact steps to reproduce this issue.</div></div>");

            userConfirmationViewModel = new UserConfirmationViewModel(stringBuilder.ToString());

            return(PartialView("_FailureConfirmation", userConfirmationViewModel));
        }
示例#30
0
        public async Task <PartialViewResult> EditUserProfile(UserEditProfileViewModel model)
        {
            var response = new HttpResponseMessage();

            if (!String.IsNullOrEmpty(model.Email))
            {
                if (model.CurrentEmail != model.Email)
                {
                    // If email is taken, add model error with following error message "The Email is unavalilable."
                    if (this.GetUserManager.FindByEmail(model.Email) != null)
                    {
                        ModelState.AddModelError("Email", "The Email is unavalilable.");
                    }
                }
            }

            if (ModelState.IsValid)
            {
                try
                {
                    // Attempt to update an email and a user name
                    var user = await this.GetUserManager.FindByNameAsync(model.UserName);

                    user.Email = model.Email;

                    var result = await this.GetUserManager.UpdateAsync(user);

                    if (result.Succeeded)
                    {
                        // If user name and email successfully updated, attempt to update FullName user claim
                        result = await this.GetUserManager.RemoveClaimAsync(user.Id, new Claim("FullName", model.CurrentFullName));

                        if (!result.Succeeded)
                        {
                            var message = String.Format("FullName claim could not be removed from user {0}.", model.UserName);

                            if (!Utilities.IsEmpty(result.Errors))
                            {
                                foreach (var error in result.Errors)
                                {
                                    message += " " + error;
                                }
                            }

                            throw new ClaimsAssignmentException(message);
                        }

                        result = await this.GetUserManager.AddClaimAsync(user.Id, new Claim("FullName", model.FirstName + " " + model.LastName));

                        if (!result.Succeeded)
                        {
                            var message = "FullName claim could not be assigned to user " + user.UserName + ".";

                            if (!Utilities.IsEmpty(result.Errors))
                            {
                                foreach (var error in result.Errors)
                                {
                                    message += " " + error;
                                }
                            }

                            throw new ClaimsAssignmentException(message);
                        }

                        if (model.UserType == UserType.Agent)
                        {
                            // If FullName user claim successfully updated, attempt to update employee profile
                            var agent = Mapper.Map <UserEditProfileViewModel, Agent>(model);

                            response = await this.GetHttpClient().PutAsJsonAsync("Agent", agent);

                            if (response.IsSuccessStatusCode)
                            {
                                agent = await response.Content.ReadAsAsync <Agent>();

                                if (agent != null)
                                {
                                    var editUserConfirmationViewModel = Mapper.Map <Agent, EditUserConfirmationViewModel>(agent);

                                    return(PartialView("_EditUserConfirmation", editUserConfirmationViewModel));
                                }
                                else
                                {
                                    throw new EmployeeUpdateException("Null is returned after updating an employee. Status Code: " + response.StatusCode);
                                }
                            }
                            else
                            {
                                throw new EmployeeUpdateException("Employee profile could not be updated. Status Code: " + response.StatusCode);
                            }
                        }
                        else if (model.UserType == UserType.Client)
                        {
                            // If FullName user claim successfully updated, attempt to update employee profile
                            var client = Mapper.Map <UserEditProfileViewModel, Client>(model);

                            response = await this.GetHttpClient().PutAsJsonAsync("Client", client);

                            if (response.IsSuccessStatusCode)
                            {
                                client = await response.Content.ReadAsAsync <Client>();

                                if (client != null)
                                {
                                    var editUserConfirmationViewModel = Mapper.Map <Client, EditUserConfirmationViewModel>(client);

                                    return(PartialView("_EditUserConfirmation", editUserConfirmationViewModel));
                                }
                                else
                                {
                                    throw new EmployeeUpdateException("Null is returned after updating an employee. Status Code: " + response.StatusCode);
                                }
                            }
                            else
                            {
                                throw new EmployeeUpdateException("Employee profile could not be updated. Status Code: " + response.StatusCode);
                            }
                        }
                        else if (model.UserType == UserType.Admin)
                        {
                            // If FullName user claim successfully updated, attempt to update employee profile
                            var admin = Mapper.Map <UserEditProfileViewModel, Admin>(model);

                            response = await this.GetHttpClient().PutAsJsonAsync("Admin", admin);

                            if (response.IsSuccessStatusCode)
                            {
                                admin = await response.Content.ReadAsAsync <Admin>();

                                if (admin != null)
                                {
                                    var editUserConfirmationViewModel = Mapper.Map <Admin, EditUserConfirmationViewModel>(admin);

                                    return(PartialView("_EditUserConfirmation", editUserConfirmationViewModel));
                                }
                                else
                                {
                                    throw new EmployeeUpdateException("Null is returned after updating an employee. Status Code: " + response.StatusCode);
                                }
                            }
                            else
                            {
                                throw new EmployeeUpdateException("Employee profile could not be updated. Status Code: " + response.StatusCode);
                            }
                        }
                    }
                    else
                    {
                        var message = "User could not be updated.";

                        if (!Utilities.IsEmpty(result.Errors))
                        {
                            foreach (var error in result.Errors)
                            {
                                message += " " + error;
                            }
                        }

                        throw new UserUpdateException(message);
                    }
                }
                catch (UserUpdateException ex)
                {
                    // Log exception
                    ErrorHandlingUtilities.LogException(ErrorHandlingUtilities.GetExceptionDetails(ex));

                    var stringBuilder = new StringBuilder();

                    stringBuilder.Append("<div class='text-center'><h4><strong>User could NOT be updated.</strong></h4></div>");

                    stringBuilder.Append("<div class='row'><div class='col-md-12'><p></p></div><div class='col-md-offset-1 col-md-11'>An exception has been caught while attempting to update a user profile. Please review an exception log for more details about the exception.</div></div>");

                    var userConfirmationViewModel = new UserConfirmationViewModel(stringBuilder.ToString());

                    return(PartialView("_Error", userConfirmationViewModel));
                }
                catch (ClaimsAssignmentException ex)
                {
                    // Log exception
                    ErrorHandlingUtilities.LogException(ErrorHandlingUtilities.GetExceptionDetails(ex));

                    var stringBuilder = new StringBuilder();

                    stringBuilder.Append("<div class='text-center'><h4><strong>Claim could NOT be assigned to the user.</strong></h4></div>");

                    stringBuilder.Append("<div class='row'><div class='col-md-12'><p></p></div><div class='col-md-offset-1 col-md-11'>An exception has been caught while attempting to assign a user claim. Please review an exception log for more details about the exception.</div></div>");

                    var userConfirmationViewModel = new UserConfirmationViewModel(stringBuilder.ToString());

                    return(PartialView("_Error", userConfirmationViewModel));
                }
                catch (EmployeeUpdateException ex)
                {
                    // Log exception
                    ErrorHandlingUtilities.LogException(ErrorHandlingUtilities.GetExceptionDetails(ex));

                    var stringBuilder = new StringBuilder();

                    stringBuilder.Append("<div class='text-center'><h4><strong>Employee could NOT be updated.</strong></h4></div>");

                    stringBuilder.Append("<div class='row'><div class='col-md-12'><p></p></div><div class='col-md-offset-1 col-md-11'>An exception has been caught while attempting to update an employee profile. Please review an exception log for more details about the exception.</div></div>");

                    var userConfirmationViewModel = new UserConfirmationViewModel(stringBuilder.ToString());

                    return(PartialView("_Error", userConfirmationViewModel));
                }
            }

            return(PartialView("_EditUserProfile", model));
        }