public ChangeRequestTask GetChangeRequestTaskByIdForEdit(int id, string currentUser)
        {
            using (var transaction = _appDataContext.Database.BeginTransaction(System.Data.IsolationLevel.Serializable))
            {
                try
                {
                    LockManager lockManager = new LockManager(_appDataContext);
                    lockManager.AcquireLock(id, "ChangeRequestTask", currentUser);

                    ChangeRequestTask crt = _appDataContext.ChangeRequestTasks.Where(c => c.ID == id).SingleOrDefault();
                    if (crt != null)
                    {
                        transaction.Commit();
                    }
                    else
                    {
                        throw new ConcurrencyException(
                                  "Entity not found. Entity man have been deleted by another user.");
                    }

                    return(crt);
                }
                catch (ConcurrencyException ex)
                {
                    transaction.Rollback();
                    string newMessage = ex.Message.Replace("Entity", "Change Request Task " + id.ToString("D5"));
                    throw new ConcurrencyException(newMessage);
                }
                catch (Exception)
                {
                    transaction.Rollback();
                    throw;
                }
            }
        }
        public int CreateChangeRequestTask(ChangeRequestTask task, string currentUser)
        {
            task.ModifiedBy = currentUser;
            task.Modified   = DateTime.Now;

            _appDataContext.ChangeRequestTasks.Add(task);
            _appDataContext.SaveChanges();

            return(task.ID);
        }
        public void UpdateChangeRequestTask(ChangeRequestTask task, string currentUser)
        {
            task.ModifiedBy = currentUser;
            task.Modified   = DateTime.Now;
            using (var transaction = _appDataContext.Database.BeginTransaction(System.Data.IsolationLevel.Serializable))
            {
                try
                {
                    var lockManager = new LockManager(_appDataContext);
                    if (lockManager.HasLock(task.ID, "ChangeRequestTask", currentUser))
                    {
                        _appDataContext.ChangeRequestTasks.Update(task);
                        _appDataContext.SaveChanges();

                        lockManager.ReleaseLock(task.ID, "ChangeRequestTask", currentUser);
                        transaction.Commit();
                    }
                    else
                    {
                        throw new ConcurrencyException("User does not have a lock on Entity.  "
                                                       + "This may be due to a timeout. "
                                                       + "Please reload record and restart editing to prevent overwriting another user's changes.");
                    }
                }
                catch (ConcurrencyException ex)
                {
                    transaction.Rollback();
                    string newMessage = ex.Message.Replace("Entity", "Change Request Task " + task.ID.ToString("D5"));
                    throw new ConcurrencyException(newMessage);
                }
                catch (Exception)
                {
                    transaction.Rollback();
                    throw;
                }
            }
        }
Esempio n. 4
0
        public static void Initialize(AppDataContext context)
        {
            context.Database.EnsureCreated();

            if (context.ChangeRequests.Any())
            {
                return;   // DB has been seeded
            }

            var cr1 = new ChangeRequest
            {
                Name       = "Open FW to External Service",
                Summary    = "Open a Firewall",
                TargetDate = DateTime.Parse("2018-01-05"),
                ActualDate = null,
                Owner      = "*****@*****.**",
                Modified   = DateTime.Parse("2017-12-15"),
                ModifiedBy = "*****@*****.**",
                Priority   = ChangeRequest.PriorityEnum.medium,
                Status     = ChangeRequest.StatusEnum.inProgress,
                Urgency    = ChangeRequest.UrgencyEnum.medium
            };
            var crt1 = new ChangeRequestTask
            {
                ChangeRequest = cr1,
                Name          = "Modify Firewall Rules",
                Summary       = "Opened port 443 on firewall to 193.169.1.1",
                Status        = ChangeRequestTask.StatusEnum.inProgress,
                CompletedDate = null,
                ModifiedBy    = "*****@*****.**",
                Modified      = DateTime.Parse("2018-01-14")
            };

            var cr2 = new ChangeRequest {
                Name       = "Create New VM for COTS",
                Summary    = "Create a VM for ABC Solution",
                TargetDate = DateTime.Parse("2018-01-02"),
                ActualDate = null,
                Owner      = "*****@*****.**",
                Modified   = DateTime.Parse("2017-01-06"),
                ModifiedBy = "*****@*****.**",
                Priority   = ChangeRequest.PriorityEnum.low,
                Status     = ChangeRequest.StatusEnum.inProgress,
                Urgency    = ChangeRequest.UrgencyEnum.medium
            };

            var crt2 = new ChangeRequestTask
            {
                ChangeRequest = cr2,
                Name          = "Provision new VM",
                Summary       = "Windows 2016 VM created",
                Status        = ChangeRequestTask.StatusEnum.completed,
                CompletedDate = null,
                ModifiedBy    = "*****@*****.**",
                Modified      = DateTime.Parse("2018-01-05")
            };
            var crt3 = new ChangeRequestTask
            {
                ChangeRequest = cr2,
                Name          = "Join VM to domain",
                Summary       = "VM joined to AD",
                Status        = ChangeRequestTask.StatusEnum.inProgress,
                CompletedDate = null,
                ModifiedBy    = "*****@*****.**",
                Modified      = DateTime.Parse("2018-01-05")
            };
            var crt4 = new ChangeRequestTask
            {
                ChangeRequest = cr2,
                Name          = "Install ABC middleware",
                Summary       = "COTS installed as per build book",
                Status        = ChangeRequestTask.StatusEnum.inProgress,
                CompletedDate = null,
                ModifiedBy    = "*****@*****.**",
                Modified      = DateTime.Parse("2018-01-05")
            };

            context.ChangeRequests.Add(cr1);
            context.ChangeRequests.Add(cr2);
            context.ChangeRequestTasks.Add(crt1);
            context.ChangeRequestTasks.Add(crt2);
            context.ChangeRequestTasks.Add(crt3);
            context.ChangeRequestTasks.Add(crt4);

            context.SaveChanges();
        }