Пример #1
0
        public async Task <Order> CreateAsync(Order model)
        {
            _context.Orders.Add(model);
            await _context.SaveChangesAsync();

            return(model);
        }
Пример #2
0
        public async Task <IActionResult> PutEventInfo(int id, EventInfo eventInfo)
        {
            if (id != eventInfo.Id)
            {
                return(BadRequest());
            }

            _context.Entry(eventInfo).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!EventInfoExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
Пример #3
0
        public async Task <IActionResult> PutEventConfirmation([FromRoute] int id, [FromBody] EventConfirmation eventConfirmation)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != eventConfirmation.Id)
            {
                return(BadRequest());
            }

            _context.Entry(eventConfirmation).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!EventConfirmationExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
Пример #4
0
        public async Task CanselEvent(int id)
        {
            var res = context.Events.FirstOrDefault(p => p.Id == id);

            context.Events.Remove(res);
            await context.SaveChangesAsync();
        }
Пример #5
0
        public async Task <T> AddAsync(T item)
        {
            await entities.AddAsync(item);

            await dbContext.SaveChangesAsync();

            return(item);
        }
Пример #6
0
        /// <summary>
        /// Logs a Revoke Access event
        /// </summary>
        /// <param name="projectId">The Id of the project for which to revoke access.</param>
        /// <param name="remoteIpAddress">The IP address of the originating request</param>
        /// <param name="azureAdObjectIdentifier">The Azure AD Object Identifier</param>
        /// <param name="revokingUser">The ApplicationUser performing the event</param>
        /// <returns>A Task object</returns>
        public async Task LogRevokeAccessEventAsync(
            int projectId,
            string remoteIpAddress,
            int targetUserId,
            Role role,
            int revokingUserId,
            string customData)
        {
            var revokeAccess = new Models.Event();

            revokeAccess.DateTime        = DateTime.UtcNow;
            revokeAccess.Type            = Enums.EventType.RevokeAccess.ToString();
            revokeAccess.OldValue        = role.ToString();
            revokeAccess.RemoteIpAddress = remoteIpAddress;
            revokeAccess.ActedByUser     = revokingUserId.ToString();
            revokeAccess.TargetUserId    = targetUserId;
            revokeAccess.ProjectId       = projectId;
            revokeAccess.Data            = "CustomData: " + customData;

            await _dbContext.Events.AddAsync(revokeAccess);

            var updatedRowCount = await _dbContext.SaveChangesAsync();

            if (updatedRowCount > 1)
            {
                // we have a problem
            }
        }
Пример #7
0
        public async Task RegisterEventAsync(string name, string subscriber)
        {
            var rawRabbitEvent = new RawRabbitEvent
            {
                Name       = name,
                Subscriber = subscriber
            };

            _context.Add(rawRabbitEvent);
            await _context.SaveChangesAsync();
        }
Пример #8
0
        public async Task <IActionResult> Create([Bind("TimeProposedId,StartTime,EndTime")] TimeProposed timeProposed)
        {
            if (ModelState.IsValid)
            {
                _context.Add(timeProposed);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(timeProposed));
        }
        public async Task <IActionResult> Create([Bind("UserId,Name,Password,CompanyId")] User user)
        {
            if (ModelState.IsValid)
            {
                _context.Add(user);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(user));
        }
Пример #10
0
        public async Task <IActionResult> Create([Bind("TaskId,TaskName,TaskDescription,done")] Models.Task task)
        {
            if (ModelState.IsValid)
            {
                _context.Add(task);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(task));
        }
Пример #11
0
        public async Task <IActionResult> ActivityCreate([Bind("ActivityId,Name,Description")] Activity activity)
        {
            if (ModelState.IsValid)
            {
                _context.Add(activity);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(ActivityEdit), "Activities", new { id = activity.ActivityId }));
            }
            return(View(activity));
        }
Пример #12
0
        public async Task <IActionResult> Create([Bind("EventId,EventName,EventDescription,EventType,ReleaseDate")] Event @event)
        {
            if (ModelState.IsValid)
            {
                _context.Add(@event);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(@event));
        }
        public async Task <IActionResult> PostEvent([FromBody] Event events)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            _context.Events.Add(events);
            await _context.SaveChangesAsync();

            return(CreatedAtAction("GetEvent", new { id = events.Id }, events));
        }
Пример #14
0
        public async Task <IActionResult> Create([Bind("CompanyId,Name,Description,UserId")] Company company)
        {
            if (ModelState.IsValid)
            {
                _context.Add(company);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["UserId"] = new SelectList(_context.users, "UserId", "UserId", company.UserId);
            return(View(company));
        }
Пример #15
0
        public async Task <User> Reqister(ReqisterDTO user)
        {
            var _user = new User()
            {
                FirstName = user.FirstName,
                LastName  = user.LastName,
                Email     = user.Email
            };
            await context.User.AddAsync(_user);

            await context.SaveChangesAsync();

            return(_user);
        }
Пример #16
0
        public async Task <ActionResult <EventInfo> > AddEvent([FromBody] EventInfo eventInfo)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    var result = await db.Events.AddAsync(eventInfo);

                    await db.SaveChangesAsync();

                    //return Created("", result.Entity); //returns the status code as 201

                    //If you want to use Action for redirection then give action name
                    //return CreatedAtAction(nameof(GetEvent), new { id = result.Entity.Id }, result.Entity); //returns the status code as 201

                    //If you want to use route for redirection then give route name
                    return(CreatedAtRoute("GetById", new { id = result.Entity.Id }, result.Entity)); //returns the status code as 201
                }
                else
                {
                    return(BadRequest(ModelState));
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Пример #17
0
        public async Task <Status> UpdatePerformanceDate(int artistId, int eventId, DateTime newPerformanceDate)
        {
            var @event = await _dbContext.Events.SingleOrDefaultAsync(x => x.IdEvent == eventId);

            if (@event is null)
            {
                return(Status.NotFound);
            }
            if (@event.StartDate < DateTime.UtcNow)
            {
                return(Status.BadRequest);
            }

            if (@event.StartDate > newPerformanceDate || @event.EndDate < newPerformanceDate)
            {
                return(Status.BadRequest);
            }

            var artistEvent =
                await _dbContext.ArtistEvents.SingleOrDefaultAsync(x =>
                                                                   x.Artist.IdArtist == artistId && x.Event.IdEvent == eventId);

            if (artistEvent is null)
            {
                return(Status.NotFound);
            }

            artistEvent.PerformanceDate = newPerformanceDate;

            await _dbContext.SaveChangesAsync();

            return(Status.NoContent);
        }
        public async Task <ActionResult <EventData> > AddEventAsync(EventData item)
        {
            TryValidateModel(item);
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            else
            {
                await db.Events.AddAsync(item);

                await db.SaveChangesAsync();

                return(CreatedAtRoute("GetEventById", new { id = item.Id }, item));
            }
        }
        public async Task <IActionResult> OnPostAsync(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            Event = await _context.Event.FirstOrDefaultAsync(m => m.Id == id);

            if (Event == null)
            {
                return(NotFound());
            }

            var userId   = _userManager.GetUserId(User); //När man är inloggad så joinar den inloggade usern ett event.
            var userJoin = await _context.MyUser
                           .Where(e => e.Id == userId)
                           .Include(a => a.JoinedEvents)
                           .FirstOrDefaultAsync();

            userJoin.JoinedEvents.Add(Event);
            await _context.SaveChangesAsync();

            return(Page());
        }
Пример #20
0
        public async Task <IActionResult> OnPostAsync(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            Event = await _context.Event.FirstOrDefaultAsync(m => m.EventId == id);

            if (Event == null)
            {
                return(NotFound());
            }

            var attendee = await _context.Attendee.Where
                               (a => a.AttendeeId == 1)
                           .Include(e => e.Event)
                           .FirstOrDefaultAsync();

            var join = await _context.Event.Where
                           (e => e.EventId == id)
                       .FirstOrDefaultAsync();

            join.SpotsAvailable = join.SpotsAvailable - 1; // Får lägga till en koll på att man inte redan är med i eventet


            attendee.Event.Add(join);
            await _context.SaveChangesAsync();

            return(Page());
        }
Пример #21
0
        public void DeletById(int id)
        {
            var deletEvent = _context.Events.Find(id);

            _context.Events.Remove(deletEvent);
            _context.SaveChangesAsync();
        }
Пример #22
0
        public async Task AddEventAsync <TEvent>(TEvent @event)
            where TEvent : IEvent <TEventId, TAggregateId>
        {
            var persistedEvent = _eventDataFactory.Create(@event);
            await DbContext.Events.AddAsync(persistedEvent);

            await DbContext.SaveChangesAsync();
        }
Пример #23
0
        public IActionResult DeleteConfirmed(int id)
        {
            var confirmedEvent = _context.Events.Find(id);

            _context.Events.Remove(confirmedEvent);
            _context.SaveChangesAsync();
            return(RedirectToAction(nameof(Index)));
        }
Пример #24
0
 public async Task <bool> SaveChangesAsync()
 {
     try
     {
         return(await context.SaveChangesAsync() > 0);
     }
     catch (Exception ex)
     {
         return(false);
     }
 }
        public async Task OnPost(string?id)
        {
            var newrole = _context.MyUser.Where(a => a.Id == id).FirstOrDefault();

            if (!_userManager.IsInRoleAsync(newrole, "organizer").Result) // Om man inte är orhganizer så blir man det när man checkar i boxen.
            {
                await _userManager.AddToRoleAsync(newrole, "organizer");

                await _userManager.RemoveFromRoleAsync(newrole, "user");

                await _context.SaveChangesAsync();
            }
            else
            {
                await _userManager.AddToRoleAsync(newrole, "user");

                await _userManager.RemoveFromRoleAsync(newrole, "organizer");

                await _context.SaveChangesAsync();
            }
            await OnGetAsync();
        }
        public static async Task SeedEventDbEntityAsync <T>(this EventDbContext context, IQueryable <EntityBase> entities, ILogger logger = null) where T : EntityBase
        {
            string seedFile = Path.Combine(AppContext.BaseDirectory, "Seed", "EventDB", $"{typeof(T).Name}.json");

            if (File.Exists(seedFile) && !(await entities.ToListAsync()).Any())
            {
                logger?.LogInformation($"Seeding {context.GetType().Name}::{typeof(T).Name} with {seedFile}");
                List <T> seedEntities = JsonConvert.DeserializeObject <List <T> >(await File.ReadAllTextAsync(seedFile));
                await context.AddRangeAsync(seedEntities);

                await context.SaveChangesAsync();

                logger?.LogInformation($"Seeding of {context.GetType().Name}::{typeof(T).Name} has completed!");
            }
        }
Пример #27
0
        public async Task <IActionResult> ActivityCreate([Bind("InviteeId,Name,ActivityId")] ActivityCreateInviteeInputModel InputModel)
        {
            if (ModelState.IsValid)
            {
                _context.Invitees.Add(new Invitee
                {
                    Name = InputModel.Name,
                    ActivityTimeInvitees = //new List<ActivityTimeInvitee>()
                    {
                        new ActivityTimeInvitee()
                        {
                            ActivityId = InputModel.ActivityId
                        }
                    }
                });


                //_context.ActivityTimeInvitees.Add(new ActivityTimeInvitee()
                //{
                //    ActivityId = InputModel.ActivityId,
                //    InviteeId = InputModel.InviteeId
                //});

                await _context.SaveChangesAsync();

                return(RedirectToAction(
                           nameof(ActivitiesController.ActivityEdit),
                           "Activities",
                           new { id = InputModel.ActivityId }));
            }

            return(View(new ActivityCreateInviteeViewModel()
            {
                ActivityId = InputModel.ActivityId
            }));
        }
Пример #28
0
        public async Task <ActionResult <EventInfo> > AddEventAsync([FromBody] EventInfo eventInfo)
        {
            if (ModelState.IsValid)
            {
                var entity = await db.Events.AddAsync(eventInfo);

                await db.SaveChangesAsync();

                return(CreatedAtRoute("GetByIdAsync", new { id = entity.Entity.Id }, entity.Entity));
            }
            else
            {
                return(BadRequest(ModelState));
            }
        }
Пример #29
0
        public async Task <IActionResult> CreateAsync(EventInfo model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }
            else
            {
                await db.Events.AddAsync(model);

                await db.SaveChangesAsync();

                return(Redirect("eventlist"));
            }
        }
Пример #30
0
        public async Task <IActionResult> CreateAsync(EventInfo eventInfo)
        {
            if (!ModelState.IsValid)
            {
                return(View("Create", eventInfo));
            }
            else
            {
                await eventDbContext.Events.AddAsync(eventInfo);

                await eventDbContext.SaveChangesAsync();

                return(RedirectToRoute("ListEvents"));
            }
        }