コード例 #1
0
        public virtual async Task <T> AddAsync(T obj)
        {
            await _db.Set <T>().AddAsync(obj);

            await _db.SaveChangesAsync();

            return(obj);
        }
コード例 #2
0
            public async Task <Unit> Handle(Command request, CancellationToken cancellationToken)
            {
                var ticket = await _context.Tickets.FindAsync(request.Id);

                if (ticket == null)
                {
                    throw new RestException(HttpStatusCode.NotFound, new { Ticket = "Could not find ticket" });
                }

                var user = await _context.Users.SingleOrDefaultAsync(x => x.UserName == _userAccessor.GetCurrentUsername());

                var assign = await _context.UserTickets.SingleOrDefaultAsync(x => x.TicketId == ticket.Id && x.UserId == user.Id);

                if (assign != null)
                {
                    throw new RestException(HttpStatusCode.BadRequest, new { Assign = "Already assign to this ticket" });
                }

                assign = new UserTicket {
                    Ticket     = ticket,
                    User       = user,
                    IsHost     = false,
                    DateJoined = DateTime.Now
                };

                _context.UserTickets.Add(assign);

                var success = await _context.SaveChangesAsync() > 0;

                if (success)
                {
                    return(Unit.Value);
                }
                throw new Exception("Problem saving the data");
            }
コード例 #3
0
ファイル: Unassign.cs プロジェクト: KaltrinaAliu/TicketSR
            public async Task <Unit> Handle(Command request, CancellationToken cancellationToken)
            {
                var ticket = await _context.Tickets.FindAsync(request.Id);

                if (ticket == null)
                {
                    throw new RestException(HttpStatusCode.NotFound, new { Ticket = "Could not find ticket" });
                }

                var user = await _context.Users.SingleOrDefaultAsync(x => x.UserName == _userAccessor.GetCurrentUsername());

                var assign = await _context.UserTickets.SingleOrDefaultAsync(x => x.TicketId == ticket.Id && x.UserId == user.Id);

                if (assign == null)
                {
                    return(Unit.Value);
                }

                if (assign.IsHost)
                {
                    throw new RestException(HttpStatusCode.BadRequest, new { Assign = "You cannot remove yourself as host" });
                }

                _context.UserTickets.Remove(assign);

                var success = await _context.SaveChangesAsync() > 0;

                if (success)
                {
                    return(Unit.Value);
                }
                throw new Exception("Problem saving the data");
            }
コード例 #4
0
            public async Task <Unit> Handle(Command request, CancellationToken cancellationToken)
            {
                var ticket = await _context.Tickets.FindAsync(request.Id);

                if (ticket == null)
                {
                    throw new RestException(HttpStatusCode.NotFound, new { ticket = "Could not find" });
                }

                ticket.Subject     = request.Subject ?? ticket.Subject;
                ticket.Issue       = request.Issue ?? ticket.Issue;
                ticket.IsDeleted   = request.IsDeleted;
                ticket.DueDate     = ticket.DueDate ?? request.DueDate;
                ticket.ClosedDate  = request.ClosedDate ?? ticket.ClosedDate;
                ticket.CreatedDate = ticket.CreatedDate;
                ticket.UpdatedDate = request.UpdatedDate;

                var success = await _context.SaveChangesAsync() > 0;

                if (success)
                {
                    return(Unit.Value);
                }
                throw new Exception("Problem editing the data");
            }
コード例 #5
0
ファイル: Create.cs プロジェクト: KaltrinaAliu/TicketSR
            public async Task <Unit> Handle(Command request, CancellationToken cancellationToken)
            {
                var ticket = new Ticket
                {
                    Id          = request.Id,
                    Subject     = request.Subject,
                    Issue       = request.Issue,
                    IsDeleted   = request.IsDeleted,
                    DueDate     = request.DueDate,
                    ClosedDate  = request.ClosedDate,
                    CreatedDate = request.CreatedDate,
                    UpdatedDate = request.UpdatedDate
                };

                _context.Tickets.Add(ticket);
                var user = await _context.Users.SingleOrDefaultAsync(x => x.UserName == _userAccessor.GetCurrentUsername());

                var data = new UserTicket
                {
                    User       = user,
                    Ticket     = ticket,
                    IsHost     = true,
                    DateJoined = DateTime.Now
                };

                _context.UserTickets.Add(data);
                var success = await _context.SaveChangesAsync() > 0;

                if (success)
                {
                    return(Unit.Value);
                }

                throw new Exception("Problem saving the data for the company");
            }
コード例 #6
0
ファイル: Create.cs プロジェクト: KaltrinaAliu/TicketSR
            public async Task <Unit> Handle(Command request, CancellationToken cancellationToken)
            {
                var role = new AppRole
                {
                    Name           = request.Name,
                    NormalizedName = request.NormalizedName,
                    IsStatic       = request.IsStatic,
                };

                _context.Roles.Add(role);
                var success = await _context.SaveChangesAsync() > 0;

                if (success)
                {
                    return(Unit.Value);
                }

                throw new Exception("Problem saving the data for the role");
            }
コード例 #7
0
ファイル: Create.cs プロジェクト: KaltrinaAliu/TicketSR
            public async Task <Unit> Handle(Command request, CancellationToken cancellationToken)
            {
                var history = new History
                {
                    Id          = request.Id,
                    Action      = request.Action,
                    CreatedDate = request.CreatedDate,
                };

                _context.Histories.Add(history);
                var success = await _context.SaveChangesAsync() > 0;

                if (success)
                {
                    return(Unit.Value);
                }

                throw new Exception("Problem saving the data for the company");
            }
コード例 #8
0
ファイル: Delete.cs プロジェクト: KaltrinaAliu/TicketSR
            public async Task <Unit> Handle(Command request, CancellationToken cancellationToken)
            {
                var ticketPriority = await _context.TicketPriorities.FindAsync(request.Id);

                if (ticketPriority == null)
                {
                    throw new RestException(HttpStatusCode.NotFound, new { ticketPriority = "Could not find" });
                }

                _context.Remove(ticketPriority);

                var success = await _context.SaveChangesAsync() > 0;

                if (success)
                {
                    return(Unit.Value);
                }
                throw new Exception("Problem saving the data");
            }
コード例 #9
0
            public async Task <Unit> Handle(Command request, CancellationToken cancellationToken)
            {
                var ticketTypes = new TicketType
                {
                    Id          = request.Id,
                    Name        = request.Name,
                    CreatedDate = request.CreatedDate,
                    UpdatedDate = request.UpdatedDate
                };

                _context.TicketTypes.Add(ticketTypes);
                var success = await _context.SaveChangesAsync() > 0;

                if (success)
                {
                    return(Unit.Value);
                }

                throw new Exception("Problem saving the data for the company");
            }
コード例 #10
0
            public async Task <Unit> Handle(Command request, CancellationToken cancellationToken)
            {
                var tags = await _context.Histories.FindAsync(request.Id);

                if (tags == null)
                {
                    throw new RestException(HttpStatusCode.NotFound, new { tags = "Could not find" });
                }

                tags.Action      = request.Action ?? tags.Action;
                tags.CreatedDate = tags.CreatedDate;


                var success = await _context.SaveChangesAsync() > 0;

                if (success)
                {
                    return(Unit.Value);
                }
                throw new Exception("Problem editing the data");
            }
コード例 #11
0
ファイル: Create.cs プロジェクト: KaltrinaAliu/TicketSR
            public async Task <Unit> Handle(Command request, CancellationToken cancellationToken)
            {
                var department = new Department
                {
                    Id          = request.Id,
                    Name        = request.Name,
                    Normalized  = request.Normalized,
                    CreatedDate = request.CreatedDate,
                    UpdatedDate = request.UpdatedDate
                };

                _context.Departments.Add(department);
                var success = await _context.SaveChangesAsync() > 0;

                if (success)
                {
                    return(Unit.Value);
                }

                throw new Exception("Problem saving the data for the company");
            }
コード例 #12
0
            public async Task <Unit> Handle(Command request, CancellationToken cancellationToken)
            {
                var comment = new Comment
                {
                    Id          = request.Id,
                    Description = request.Description,
                    IsDeleted   = request.IsDeleted,
                    CreatedDate = request.CreatedDate,
                    UpdatedDate = request.UpdatedDate
                };

                _context.Comments.Add(comment);
                var success = await _context.SaveChangesAsync() > 0;

                if (success)
                {
                    return(Unit.Value);
                }

                throw new Exception("Problem saving the data for the company");
            }
コード例 #13
0
ファイル: Create.cs プロジェクト: KaltrinaAliu/TicketSR
            public async Task <Unit> Handle(Command request, CancellationToken cancellationToken)
            {
                var attachment = new Attachment
                {
                    Id          = request.Id,
                    Name        = request.Name,
                    Path        = request.Path,
                    Type        = request.Type,
                    CreatedDate = request.CreatedDate,
                    UpdatedDate = request.UpdatedDate
                };

                _context.Attachments.Add(attachment);
                var success = await _context.SaveChangesAsync() > 0;

                if (success)
                {
                    return(Unit.Value);
                }

                throw new Exception("Problem saving the data for the company");
            }
コード例 #14
0
ファイル: Edit.cs プロジェクト: KaltrinaAliu/TicketSR
            public async Task <Unit> Handle(Command request, CancellationToken cancellationToken)
            {
                var role = await _context.Roles.FindAsync(request.Id);

                if (role == null)
                {
                    throw new RestException(HttpStatusCode.NotFound, new { role = "Could not find" });
                }

                role.Name           = request.Name ?? role.Name;
                role.NormalizedName = request.NormalizedName ?? role.NormalizedName;
                role.IsStatic       = request.IsStatic;


                var success = await _context.SaveChangesAsync() > 0;

                if (success)
                {
                    return(Unit.Value);
                }
                throw new Exception("Problem editing the data");
            }
コード例 #15
0
            public async Task <Unit> Handle(Command request, CancellationToken cancellationToken)
            {
                var notification = new Notification
                {
                    Id          = request.Id,
                    Title       = request.Title,
                    Message     = request.Message,
                    Type        = request.Type,
                    Unread      = request.Unread,
                    CreatedDate = request.CreatedDate
                };

                _context.Notifications.Add(notification);
                var success = await _context.SaveChangesAsync() > 0;

                if (success)
                {
                    return(Unit.Value);
                }

                throw new Exception("Problem saving the data for the company");
            }
コード例 #16
0
ファイル: Edit.cs プロジェクト: KaltrinaAliu/TicketSR
            public async Task <Unit> Handle(Command request, CancellationToken cancellationToken)
            {
                var team = await _context.Teams.FindAsync(request.Id);

                if (team == null)
                {
                    throw new RestException(HttpStatusCode.NotFound, new { team = "Could not find" });
                }

                team.Name        = request.Name ?? team.Name;
                team.CreatedDate = team.CreatedDate;
                team.UpdatedDate = request.UpdatedDate;


                var success = await _context.SaveChangesAsync() > 0;

                if (success)
                {
                    return(Unit.Value);
                }
                throw new Exception("Problem editing the data");
            }
コード例 #17
0
            public async Task <Unit> Handle(Command request, CancellationToken cancellationToken)
            {
                var note = await _context.Notes.FindAsync(request.Id);

                if (note == null)
                {
                    throw new RestException(HttpStatusCode.NotFound, new { note = "Could not find" });
                }

                note.Description = request.Description ?? note.Description;
                note.IsDeleted   = request.IsDeleted;
                note.CreatedDate = note.CreatedDate;
                note.UpdatedDate = request.UpdatedDate;


                var success = await _context.SaveChangesAsync() > 0;

                if (success)
                {
                    return(Unit.Value);
                }
                throw new Exception("Problem editing the data");
            }
コード例 #18
0
            public async Task <Unit> Handle(Command request, CancellationToken cancellationToken)
            {
                var notification = await _context.Notifications.FindAsync(request.Id);

                if (notification == null)
                {
                    throw new RestException(HttpStatusCode.NotFound, new { notification = "Could not find" });
                }

                notification.Title       = request.Title ?? notification.Title;
                notification.Message     = request.Message ?? notification.Message;
                notification.Type        = request.Type ?? notification.Type;
                notification.Unread      = request.Unread;
                notification.CreatedDate = notification.CreatedDate;

                var success = await _context.SaveChangesAsync() > 0;

                if (success)
                {
                    return(Unit.Value);
                }
                throw new Exception("Problem editing the data");
            }
コード例 #19
0
            public async Task <Unit> Handle(Command request, CancellationToken cancellationToken)
            {
                var role = await _context.Roles.FindAsync(request.Id);

                if (role == null)
                {
                    throw new RestException(HttpStatusCode.NotFound, new { role = "Could not find" });
                }
                if (role.IsStatic == true)
                {
                    throw new RestException(HttpStatusCode.NotFound, new { role = "Could not delete a static role" });
                }

                _context.Remove(role);

                var success = await _context.SaveChangesAsync() > 0;

                if (success)
                {
                    return(Unit.Value);
                }
                throw new Exception("Problem saving the data");
            }
コード例 #20
0
            public async Task <Unit> Handle(Command request, CancellationToken cancellationToken)
            {
                var department = await _context.Departments.FindAsync(request.Id);

                if (department == null)
                {
                    throw new RestException(HttpStatusCode.NotFound, new { department = "Could not find" });
                }

                department.Name        = request.Name ?? department.Name;
                department.Normalized  = request.Normalized ?? department.Normalized;
                department.CreatedDate = department.CreatedDate;
                department.UpdatedDate = request.UpdatedDate;


                var success = await _context.SaveChangesAsync() > 0;

                if (success)
                {
                    return(Unit.Value);
                }
                throw new Exception("Problem editing the data");
            }
コード例 #21
0
ファイル: Edit.cs プロジェクト: KaltrinaAliu/TicketSR
            public async Task <Unit> Handle(Command request, CancellationToken cancellationToken)
            {
                var ticketPriority = await _context.TicketPriorities.FindAsync(request.Id);

                if (ticketPriority == null)
                {
                    throw new RestException(HttpStatusCode.NotFound, new { ticketPriority = "Could not find" });
                }

                ticketPriority.Name        = request.Name ?? ticketPriority.Name;
                ticketPriority.IsDefault   = request.IsDefault;
                ticketPriority.Color       = request.Color ?? ticketPriority.Color;
                ticketPriority.CreatedDate = ticketPriority.CreatedDate;
                ticketPriority.UpdatedDate = request.UpdatedDate;


                var success = await _context.SaveChangesAsync() > 0;

                if (success)
                {
                    return(Unit.Value);
                }
                throw new Exception("Problem editing the data");
            }
コード例 #22
0
ファイル: Edit.cs プロジェクト: KaltrinaAliu/TicketSR
            public async Task <Unit> Handle(Command request, CancellationToken cancellationToken)
            {
                var attachment = await _context.Attachments.FindAsync(request.Id);

                if (attachment == null)
                {
                    throw new RestException(HttpStatusCode.NotFound, new { attachment = "Could not find" });
                }

                attachment.Name        = request.Name ?? attachment.Name;
                attachment.Path        = request.Path ?? attachment.Path;
                attachment.Type        = request.Type ?? request.Type;
                attachment.CreatedDate = attachment.CreatedDate;
                attachment.UpdatedDate = request.UpdatedDate;


                var success = await _context.SaveChangesAsync() > 0;

                if (success)
                {
                    return(Unit.Value);
                }
                throw new Exception("Problem editing the data");
            }
コード例 #23
0
ファイル: Edit.cs プロジェクト: KaltrinaAliu/TicketSR
            public async Task <Unit> Handle(Command request, CancellationToken cancellationToken)
            {
                var company = await _context.Companies.FindAsync(request.Id);

                if (company == null)
                {
                    throw new RestException(HttpStatusCode.NotFound, new { company = "Could not find" });
                }

                company.Name        = request.Name ?? company.Name;
                company.Description = request.Description ?? company.Description;
                company.IsActive    = request.IsActive ?? company.IsActive;
                company.CreatedDate = company.CreatedDate;
                company.UpdatedDate = request.UpdatedDate;


                var success = await _context.SaveChangesAsync() > 0;

                if (success)
                {
                    return(Unit.Value);
                }
                throw new Exception("Problem editing the data");
            }