Пример #1
0
        public bool UnAssign(int userId, int id, ref object dtoItem, out Library.DTO.Notification notification)
        {
            DTO.AssignData dtoAssign = ((Newtonsoft.Json.Linq.JObject)dtoItem).ToObject <DTO.AssignData>();
            notification = new Library.DTO.Notification()
            {
                Type = Library.DTO.NotificationType.Success
            };
            try
            {
                using (DevRequestMngEntities context = CreateContext())
                {
                    DevRequestHistory dbHistory = null;
                    DevRequest        dbRequest = context.DevRequest.FirstOrDefault(o => o.DevRequestID == id);
                    if (dbRequest != null)
                    {
                        dbHistory = new DevRequestHistory();
                        dbRequest.DevRequestHistory.Add(dbHistory);
                    }
                    else
                    {
                        throw new Exception("Dev request not found!");
                    }

                    DevRequestAssignment dbAssignment = dbRequest.DevRequestAssignment.FirstOrDefault(o => o.AssignedTo == dtoAssign.AssignedTo);
                    if (dbAssignment != null) // person is already added
                    {
                        dbRequest.DevRequestAssignment.Remove(dbAssignment);
                        context.DevRequestAssignment.Remove(dbAssignment);
                    }
                    else
                    {
                        throw new Exception("Person is not assigned!");
                    }

                    Support.DTO.User dtoUser = supportFactory.GetUsers().FirstOrDefault(o => o.UserId == dtoAssign.AssignedTo);
                    if (dtoUser == null) // check if user is exists in the system
                    {
                        throw new Exception("Person not found!");
                    }

                    dbHistory.Comment     = dtoAssign.Comment;
                    dbHistory.UpdatedBy   = userId;
                    dbHistory.UpdatedDate = DateTime.Now;
                    dbHistory.DevRequestHistoryActionID = 7; // 7 : un-assign
                    dbHistory.ActionDescription         = "REMOVE PERSON: " + dtoUser.FullName + " FROM TASK ASSIGNMENT";

                    // send notify email
                    string emailSubject = "TASK REQUEST: [UNASSIGN] " + dbRequest.Title;
                    string emailBody    = "";
                    emailBody += "ID: " + dbRequest.DevRequestID.ToString() + "<br/>";
                    emailBody += "TITLE: " + dbRequest.Title + "<br/>";
                    emailBody += "UPDATED BY: " + supportFactory.GetUsers().FirstOrDefault(o => o.UserId == userId).FullName + "<br/>";
                    emailBody += dbHistory.ActionDescription;
                    SendNotification(context, dbRequest, emailSubject, emailBody);

                    context.SaveChanges();
                    return(true);
                }
            }
            catch (Exception ex)
            {
                notification = new Library.DTO.Notification()
                {
                    Message = ex.Message, Type = Library.DTO.NotificationType.Error
                };
                return(false);
            }
        }
Пример #2
0
        public bool UpdateEstHourSpend(int userId, int id, object dtoItem, out Library.DTO.Notification notification)
        {
            List <DTO.DevRequestAssignment> dtoAssignments = ((Newtonsoft.Json.Linq.JArray)dtoItem).ToObject <List <DTO.DevRequestAssignment> >();

            notification = new Library.DTO.Notification()
            {
                Type = Library.DTO.NotificationType.Success
            };
            try
            {
                using (DevRequestMngEntities context = CreateContext())
                {
                    DevRequestHistory dbHistory = null;
                    DevRequest        dbRequest = context.DevRequest.FirstOrDefault(o => o.DevRequestID == id);
                    if (dbRequest != null)
                    {
                        dbHistory = new DevRequestHistory();
                        dbRequest.DevRequestHistory.Add(dbHistory);
                    }
                    else
                    {
                        notification.Message = "Dev request not found!";
                        return(false);
                    }

                    if (dbRequest == null)
                    {
                        throw new Exception("Request not found!");
                    }

                    foreach (DTO.DevRequestAssignment dtoAssignment in dtoAssignments)
                    {
                        DevRequestAssignment dbAssignment = dbRequest.DevRequestAssignment.FirstOrDefault(o => o.DevRequestAssignmentID == dtoAssignment.DevRequestAssignmentID);
                        if (dbAssignment != null)
                        {
                            dbAssignment.EstWorkingHour    = dtoAssignment.EstWorkingHour;
                            dbAssignment.ActualWorkingHour = dtoAssignment.ActualWorkingHour;
                        }
                    }

                    dbHistory.Comment     = string.Empty;
                    dbHistory.UpdatedBy   = userId;
                    dbHistory.UpdatedDate = DateTime.Now;
                    dbHistory.DevRequestHistoryActionID = 6;  // 6 : set est end date
                    dbHistory.ActionDescription         = "SET HOUR SPEND (EST/ACTUAL)";

                    // send notify email
                    string emailSubject = "TASK REQUEST: [SET HOUR SPEND] " + dbRequest.Title;
                    string emailBody    = "";
                    emailBody += "ID: " + dbRequest.DevRequestID.ToString() + "<br/>";
                    emailBody += "TITLE: " + dbRequest.Title + "<br/>";
                    emailBody += "UPDATOR: " + supportFactory.GetUsers().FirstOrDefault(o => o.UserId == userId).FullName + "<br/>";
                    emailBody += dbHistory.ActionDescription;
                    SendNotification(context, dbRequest, emailSubject, emailBody);

                    context.SaveChanges();
                    return(true);
                }
            }
            catch (Exception ex)
            {
                notification = new Library.DTO.Notification()
                {
                    Message = ex.Message, Type = Library.DTO.NotificationType.Error
                };
                return(false);
            }
        }
Пример #3
0
        public bool Assign(int userId, int id, ref object dtoItem, out Library.DTO.Notification notification)
        {
            DTO.AssignData dtoAssign = ((Newtonsoft.Json.Linq.JObject)dtoItem).ToObject <DTO.AssignData>();
            notification = new Library.DTO.Notification()
            {
                Type = Library.DTO.NotificationType.Success
            };
            try
            {
                using (DevRequestMngEntities context = CreateContext())
                {
                    DevRequestHistory    dbHistory = null;
                    DevRequestAssignment dbAssign  = null;
                    DevRequest           dbRequest = context.DevRequest.FirstOrDefault(o => o.DevRequestID == id);
                    if (dbRequest != null)
                    {
                        dbHistory = new DevRequestHistory();
                        dbAssign  = new DevRequestAssignment();
                        dbRequest.DevRequestHistory.Add(dbHistory);
                        dbRequest.DevRequestAssignment.Add(dbAssign);
                    }
                    else
                    {
                        notification.Message = "Dev request not found!";
                        return(false);
                    }

                    if (dbRequest.DevRequestAssignment.FirstOrDefault(o => o.AssignedTo == dtoAssign.AssignedTo) != null) // person is already added
                    {
                        notification.Message = "Person is already in the list!";
                        return(false);
                    }

                    Support.DTO.User dtoUser = supportFactory.GetUsers().FirstOrDefault(o => o.UserId == dtoAssign.AssignedTo);
                    if (dtoUser == null) // check if user is exists in the system
                    {
                        notification.Message = "Person not found!";
                        return(false);
                    }

                    dbHistory.Comment     = dtoAssign.Comment;
                    dbHistory.UpdatedBy   = userId;
                    dbHistory.UpdatedDate = DateTime.Now;
                    dbHistory.DevRequestHistoryActionID = 2; // 2 : assign
                    dbHistory.ActionDescription         = "ASSGIN TASK TO " + dtoUser.FullName + " ";
                    if (dtoAssign.IsPersonInCharge)
                    {
                        dbHistory.ActionDescription += "(PIC)";
                    }

                    dbAssign.AssignedTo = dtoAssign.AssignedTo;
                    if (dtoAssign.IsPersonInCharge)
                    {
                        dbRequest.DevRequestAssignment.ToList().ForEach(o => o.IsPersonInCharge = false);
                    }
                    dbAssign.IsPersonInCharge = dtoAssign.IsPersonInCharge;

                    // send notify email
                    string emailSubject = "TASK REQUEST: [ASSIGN] " + dbRequest.Title;
                    string emailBody    = "";
                    emailBody += "ID: " + dbRequest.DevRequestID.ToString() + "<br/>";
                    emailBody += "TITLE: " + dbRequest.Title + "<br/>";
                    emailBody += "ASSIGNED BY: " + supportFactory.GetUsers().FirstOrDefault(o => o.UserId == userId).FullName + "<br/>";
                    emailBody += dbHistory.ActionDescription;
                    SendNotification(context, dbRequest, emailSubject, emailBody);

                    context.SaveChanges();
                    dtoItem = GetData(id, out notification).Data;
                    return(true);
                }
            }
            catch (Exception ex)
            {
                notification = new Library.DTO.Notification()
                {
                    Message = ex.Message, Type = Library.DTO.NotificationType.Error
                };
                return(false);
            }
        }