Exemple #1
0
        public static void Create(string userId, string title, string description, int projectId, int ticketTypeId, int ticketPriorityId, int ticketStatusId)
        {
            ApplicationDbContext db = new ApplicationDbContext();
            Ticket ticket           = new Ticket
            {
                Title            = title,
                Description      = description,
                ProjectId        = projectId,
                Created          = DateTime.Now,
                Updated          = DateTime.Now,
                TicketTypeId     = ticketTypeId,
                TicketPriorityId = ticketPriorityId,
                TicketStatusId   = ticketStatusId,
                OwnerUserId      = userId
            };

            db.Tickets.Add(ticket);
            db.SaveChanges();

            Ticket newTicket = db.Tickets.OrderByDescending(p => p.Created).FirstOrDefault();

            var dbEntityEntry = db.Entry(newTicket);

            foreach (var property in dbEntityEntry.OriginalValues.PropertyNames)
            {
                string newValue = "";
                if (dbEntityEntry.CurrentValues.GetValue <object>(property) != null)
                {
                    dbEntityEntry.CurrentValues.GetValue <object>(property).ToString();
                    TicketHistoryHelper.SetTicketHistory(ticket.Id, property, "New Record", newValue, HttpContext.Current.User.Identity.GetUserId());
                }
            }

            db.Dispose();
        }
Exemple #2
0
        public static void Edit(int id, string userId, string title, string description, int ticketTypeId, int ticketPriorityId, int ticketStatusId, string assignedUserId)
        {
            ApplicationDbContext db = new ApplicationDbContext();
            Ticket ticket           = db.Tickets.Find(id);

            if (ticket != null)
            {
                if (title != null)
                {
                    ticket.Title = title;
                }
                if (description != null)
                {
                    ticket.Description = description;
                }
                //ticket.OwnerUserId = userId;
                //ticket.ProjectId = ticket.ProjectId;
                if (ticketTypeId != 0)
                {
                    ticket.TicketTypeId = ticketTypeId;
                }
                if (ticketPriorityId != 0)
                {
                    ticket.TicketPriorityId = ticketPriorityId;
                }
                if (ticketStatusId != 0)
                {
                    ticket.TicketStatusId = ticketStatusId;
                }
                ticket.Updated = DateTime.Now;
                if (assignedUserId != null)
                {
                    ticket.AssignedToUserId = assignedUserId;
                }

                var entityEntry = db.Entry(ticket);
                foreach (var property in entityEntry.OriginalValues.PropertyNames)
                {
                    string oldVAlue = "";
                    string newValue = "";

                    if (entityEntry.OriginalValues.GetValue <object>(property) != null)
                    {
                        oldVAlue = entityEntry.OriginalValues.GetValue <object>(property).ToString();
                    }

                    if (entityEntry.CurrentValues.GetValue <object>(property) != null)
                    {
                        newValue = entityEntry.CurrentValues.GetValue <object>(property).ToString();
                    }

                    if (newValue != null && !oldVAlue.Equals(newValue))
                    {
                        entityEntry.Property(property).IsModified = true;
                        TicketHistoryHelper.SetTicketHistory(id, property, oldVAlue, newValue, HttpContext.Current.User.Identity.GetUserId());
                    }
                }

                db.SaveChanges();
                db.Dispose();
            }
        }