Example #1
0
        PutAsync(HelpDeskTickets UpdatedHelpDeskTickets)
        {
            // Get the existing record
            // Note: Caller must have the TicketGuid
            var existingTicket =
                helpdeskContext.HelpDeskTickets
                .Where(x => x.TicketGuid ==
                       UpdatedHelpDeskTickets.TicketGuid)
                .FirstOrDefault();

            if (existingTicket != null)
            {
                existingTicket.TicketDate =
                    UpdatedHelpDeskTickets.TicketDate;

                existingTicket.TicketDescription =
                    UpdatedHelpDeskTickets.TicketDescription;

                existingTicket.TicketGuid =
                    UpdatedHelpDeskTickets.TicketGuid;

                existingTicket.TicketRequesterEmail =
                    UpdatedHelpDeskTickets.TicketRequesterEmail;

                existingTicket.TicketStatus =
                    UpdatedHelpDeskTickets.TicketStatus;

                // Insert any new TicketDetails
                if (UpdatedHelpDeskTickets.HelpDeskTicketDetails != null)
                {
                    foreach (var item in
                             UpdatedHelpDeskTickets.HelpDeskTicketDetails)
                    {
                        if (item.Id == 0)
                        {
                            // Create New HelpDeskTicketDetails record
                            HelpDeskTicketDetails newHelpDeskTicketDetails =
                                new HelpDeskTicketDetails();
                            newHelpDeskTicketDetails.HelpDeskTicketId =
                                UpdatedHelpDeskTickets.Id;
                            newHelpDeskTicketDetails.TicketDetailDate =
                                DateTime.Now;
                            newHelpDeskTicketDetails.TicketDescription =
                                item.TicketDescription;

                            helpdeskContext.HelpDeskTicketDetails
                            .Add(newHelpDeskTicketDetails);
                        }
                    }
                }

                helpdeskContext.SaveChanges();
            }
            else
            {
                return(Task.FromResult(false));
            }

            return(Task.FromResult(true));
        }
Example #2
0
        public Task Post(HelpDeskTickets newHelpDeskTickets)
        {
            // Add a new Help Desk Ticket
            helpdeskContext.HelpDeskTickets.Add(newHelpDeskTickets);
            helpdeskContext.SaveChanges();

            return(Task.FromResult(newHelpDeskTickets));
        }
Example #3
0
        public async Task <List <HelpDeskTickets> > GetHelpDeskTickets(int Month, int Year)
        {
            List <HelpDeskTickets> list = new List <HelpDeskTickets>();

            using (var ctx = new DbEntities())
            {
                var helpTicketData = await ctx.HelpDeskTickets.Where(x => x.Month == Month && x.Year == Year).ToListAsync();

                if (helpTicketData != null)
                {
                    foreach (var item in helpTicketData)
                    {
                        HelpDeskTickets obj = new HelpDeskTickets();
                        obj.Id       = item.Id;
                        obj.Category = item.Category;
                        obj.Value    = item.Value;
                        list.Add(obj);
                    }
                }
                return(list);
            }
        }