Ejemplo n.º 1
0
        public IActionResult Update(int id, EditEventViewModel model)
        {
            if (!ModelState.IsValid)
            {
                ViewData["Users"] = _databaseContext.Users.ToList();
                return(View(nameof(Edit), model));
            }
            var Event = _databaseContext.Events
                        .Include(e => e.EventUser)
                        .ThenInclude(eu => eu.Users)
                        .First(g => g.Id == id);

            Event.Title       = model.Event.Title;
            Event.Description = model.Event.Description;
            Event.Date        = model.Event.Date;
            Event.Time        = model.Event.Time;

            TempData["Success"] = true;
            Event.EventUser.Clear();
            var newUsers = _databaseContext.Users.Where(u => model.UserIds.Contains(u.Id)).ToList();

            foreach (var user in newUsers)
            {
                Event.EventUser.Add(new EventUser {
                    Users = user, Events = Event
                });
            }
            _databaseContext.SaveChanges();

            return(RedirectToAction(nameof(Index)));
        }
Ejemplo n.º 2
0
        public async Task <IActionResult> Edit(int id)
        {
            var evt = await _dbContext.Events.FindAsync(id);

            if (evt == null)
            {
                _logger.LogInformation("Could not find event ID '{id}'", id);
                return(RedirectToAction(nameof(Index)));
            }

            if (!(await _authorizationService.AuthorizeAsync(User, evt, Policies.EventAdmin)).Succeeded)
            {
                return(Unauthorized());
            }

            var model = new EditEventViewModel
            {
                Id                      = evt.Id,
                Name                    = evt.Name,
                Description             = evt.Description,
                StartOn                 = evt.StartOn,
                EndOn                   = evt.EndOn,
                DisplayOn               = evt.DisplayOn,
                HideBidderNames         = evt.HideBidderNames,
                DefaultMinimumBidAmount = evt.DefaultMinimumBidAmount,
            };

            return(View(model));
        }
Ejemplo n.º 3
0
        public ActionResult Edit(EditEventViewModel viewModel)
        {
            if (!ModelState.IsValid)
            {
                var context = new CheckInDbContext();
                ViewBag.States = context.States.ToList();
                return(View(viewModel));
            }

            using (var context = new CheckInDbContext())
            {
                var eventDb = context.Events.Include(s => s.Address).FirstOrDefault(x => x.Id == viewModel.Id);
                eventDb.Address.AddressName = viewModel.Address;
                eventDb.Address.StateId     = viewModel.StateId;
                eventDb.Address.CityName    = viewModel.City;
                eventDb.Address.ZipCode     = viewModel.ZipCode;
                eventDb.Date         = Convert.ToDateTime(string.Format("{0},{1}", viewModel.Date, viewModel.Time));
                eventDb.PlaceOfEvent = viewModel.PlaceOfEvent;
                eventDb.Name         = viewModel.NameOfEvent;
                eventDb.ModifiedOn   = DateTime.Now;
                eventDb.Modifiedby   = User.Identity.GetUserId();

                context.SaveChanges();
            }

            return(RedirectToAction("Index"));
        }
Ejemplo n.º 4
0
        // [Authorize]
        public async Task <IActionResult> Patch([FromRoute] int id, [FromBody] EditEventViewModel orgEvent)
        {
            if (ModelState.IsValid)
            {
                var user = await GetCurrentUserAsync();

                Event evt = await context.Event.Include(e => e.Organization).ThenInclude(o => o.Organizer).Where(e => e.EventId == id && e.Organization.Organizer.Id == user.Id).SingleOrDefaultAsync();

                if (evt == null)
                {
                    return(BadRequest());
                }

                evt.Name        = orgEvent.Name;
                evt.Description = orgEvent.Description;
                evt.City        = orgEvent.City;
                evt.State       = orgEvent.State;
                evt.Address     = orgEvent.Address;
                evt.ZipCode     = orgEvent.ZipCode;
                evt.Date        = orgEvent.Date;
                evt.StartTime   = orgEvent.StartTime;
                evt.EndTime     = orgEvent.EndTime;

                context.Entry(evt).State = EntityState.Modified;
                context.Update(evt);
                await context.SaveChangesAsync();

                List <EventMember> eMembers = await context.EventMember.Where(m => m.EventId == evt.EventId).ToListAsync();

                EventViewModel model = new EventViewModel(evt, eMembers);

                return(Json(model));
            }
            return(BadRequest(ModelState));
        }
Ejemplo n.º 5
0
        public async Task <IActionResult> Edit(int id, [Bind("Title,Details,CreatedById,StartTime,EndTime,MaxGroupSize,TransportId,TripId,IsDeleted,DeletedOn,Id,CreatedOn,ModifiedOn")] EditEventViewModel input)
        {
            if (id != input.Id)
            {
                return(this.NotFound());
            }

            if (this.ModelState.IsValid)
            {
                try
                {
                    await this.eventsService.UpdateAsync(input);
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!this.eventsService.Exists(input.Id))
                    {
                        return(this.NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }

                return(this.RedirectToAction(nameof(this.Index)));
            }

            var transportItems = this.transportService.GetAllTransportTypes();

            input.TransportItems = transportItems;

            return(this.View(input));
        }
        public async Task <IActionResult> Edit([FromBody] EditEventViewModel editEventViewModel)
        {
            logger.LogInformation($"POST Request {HttpContext.Request.Headers[":path"]}. Body: {JsonConvert.SerializeObject(editEventViewModel)}");

            var eventId = editEventViewModel.Id;

            if (!await accessChecker.CanManageEvent(eventId))
            {
                throw new HttpStatusException(HttpStatusCode.Forbidden, CommonErrorMessages.Forbidden);
            }

            var @event = await context.Events.Include(e => e.Owner).FirstOrDefaultAsync(e => e.Id == eventId);

            var config = new MapperConfiguration(cfg => cfg.CreateMap <EditEventViewModel, Event>()
                                                 .ForMember("Teams", opt => opt.Ignore())
                                                 .ForMember("Owner", opt => opt.Ignore()));
            var mapper = new Mapper(config);

            mapper.Map(editEventViewModel, @event);

            try
            {
                context.Update(@event);
                await context.SaveChangesAsync();
            }
            catch (System.Exception)
            {
                throw new HttpStatusException(HttpStatusCode.InternalServerError, CommonErrorMessages.SaveChanges);
            }

            return(Json(@event));
        }
Ejemplo n.º 7
0
        public IActionResult SubmitEditEventForm(EditEventViewModel editEventViewModel)
        {
            if (ModelState.IsValid)
            {
                EventCategory theCategory = context.EventCategories.Find(editEventViewModel.CategoryId);
                Event         eventToEdit = context.Events.Find(editEventViewModel.IdForEditEvent);
                eventToEdit.Name         = editEventViewModel.Name;
                eventToEdit.Location     = editEventViewModel.Location;
                eventToEdit.NumAttendees = editEventViewModel.NumAttendees;
                eventToEdit.Description  = editEventViewModel.Description;
                //Type = addEventViewModel.Type,
                eventToEdit.Category     = theCategory;
                eventToEdit.ContactEmail = editEventViewModel.ContactEmail;

                context.SaveChanges();
                return(Redirect("/Events"));
            }

            List <EventCategory> categories = context.EventCategories.ToList();

            editEventViewModel.Categories = new List <SelectListItem>();
            foreach (var category in categories)
            {
                editEventViewModel.Categories.Add(new SelectListItem
                {
                    Value = category.Id.ToString(),
                    Text  = category.Name
                });
            }
            return(View("/Events/Edit", editEventViewModel));
        }
Ejemplo n.º 8
0
        public ActionResult Edit(EditEventViewModel model, HttpPostedFileBase imagefile)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }
            var _event = Mapper.Map <EditEventViewModel, Event>(model);


            _event.UserId = UserManager.Users.Where(u => u.UserName == User.Identity.Name).Select(x => x.Id).FirstOrDefault();
            var result = new Event();

            using (var repo = new Repository <Event>())
                using (var eventRepo = new Repository <Event>())
                {
                    if (imagefile != null)
                    {
                        _event.FileName    = imagefile.FileName;
                        _event.ContentType = imagefile.ContentType;
                        _event.Image       = new byte[imagefile.ContentLength];
                        imagefile.InputStream.Read(_event.Image, 0, imagefile.ContentLength);
                    }
                    else
                    {
                        var _value = repo.GetById(model.Id);
                        _event.FileName    = _value.FileName;
                        _event.ContentType = _value.ContentType;
                        _event.Image       = _value.Image;
                    }
                    result = eventRepo.InsertOrUpdate(_event);
                }
            return(RedirectToAction("Detail", new { id = result.Id }));
        }
        public IActionResult EditEvent(long Id)
        {
            Event events = eventRepository.GetEventById(Id);

            if (events == null)
            {
                ViewBag.ErrorMessage = $"The event with reference id = { Id } could not be found";
                return(View("error"));
            }

            EditEventViewModel model = new EditEventViewModel
            {
                Id                = events.Id,
                Title             = events.Title,
                Description       = events.Description,
                Date              = events.Date,
                StartTime         = events.StartTime,
                EndTime           = events.EndTime,
                EventGuests       = events.EventGuests,
                Fee               = Convert.ToDecimal(events.Fee),
                ExistingPhotoPath = events.Image,
                Sponsor           = events.Sponsor,
                Speaker           = events.Speaker,
                EventCategoryId   = events.EventCategoryId,
                LocationId        = events.LocationId
            };

            GetAllEventCategories(model);
            GetAllLocations(model);
            return(View(model));
        }
Ejemplo n.º 10
0
        public async Task <ActionResult> EditEvent(int id, EditEventViewModel model)
        {
            if (ModelState.IsValid)
            {
                // Converting the block
                ClanEvent clanEvent = new ClanEvent
                {
                    Id               = id,
                    Title            = model.EventName,
                    EventDateAndTime = model.EventDate,
                    Description      = model.Description,
                    Game             = model.Game,
                    Location         = model.Location,
                };

                // Saving the model based 0n if it has a image
                if (model.Image == null)
                {
                    await EventManager.UpdateClanEventAsync(clanEvent);
                }
                else
                {
                    await EventManager.UpdateClanEventAsync(clanEvent, Bitmap.FromStream(model.Image.InputStream));
                }

                return(RedirectToAction("Events"));
            }

            ModelState.AddModelError("Model", "You did not fill in everything");
            return(View(model));
        }
Ejemplo n.º 11
0
        public string EditEvent(EditEventViewModel model)
        {
            var ev = this.FindEventById(model.Id);

            mapper.Map(model, ev);
            this.repository.SaveChangesAsync();
            return(string.Format(GlobalConstants.EditEvent, model.Name));
        }
Ejemplo n.º 12
0
        public ActionResult AddEvent(EditEventViewModel viewModel)
        {
            var olympicEvent = viewModel.Map();

            _eventService.InsertOlympicEvent(olympicEvent);

            return(RedirectToAction(nameof(EventManagement)));
        }
Ejemplo n.º 13
0
        public async Task <IActionResult> Edit(EditEventViewModel input)
        {
            await this.eventsService.UpdateAsync(input);

            var eventId = input.Id;

            return(this.RedirectToAction(nameof(this.GetById), new { id = eventId }));
        }
Ejemplo n.º 14
0
        //
        // GET: /KultiEvents/Edit/5
        public ActionResult Edit(int id = 0)
        {
            Events events = db.Events.Single(e => e.EventId == id);

            if (events == null)
            {
                return(HttpNotFound());
            }

            var  hlpView   = new HelpersViewModel();
            bool isInGroup = false;
            int  GrpId     = events.EvGroupId ?? 0;

            if (HlpView.GetUserId(User.Identity.Name) == events.EvUserId || events.EvGroupId < 1)
            {
                isInGroup = true;
            }

            if (!isInGroup) //make shure that current user belongs to group who created event
            {
                var           roles = (SimpleRoleProvider)Roles.Provider;
                List <string> getRolesOfCurrentUser = roles.GetRolesForUser(User.Identity.Name).ToList();
                foreach (string s in getRolesOfCurrentUser)
                {
                    if (HlpView.GetParamValueByPk(GrpId) == s)
                    {
                        isInGroup = true;
                        break;
                    }
                }
            }

            if (!isInGroup)
            {
                ViewBag.NotAllowed = "Du kannst den Event nicht ändern, da er von einer anderen Gruppe erstellt wurde.";
                return(View("Index", db.Events.ToList()));
            }

            var viewModel = new EditEventViewModel
            {
                CEvents = events,
                Status  = HlpView.Status,
                Type    = HlpView.EventType,
                Size    = HlpView.EventSize,
                Group   = HlpView.Group,
                Agency  = hlpView.Agency,
                SelectedLocationValue = events.EvLocation,
                SelectedStatusValue   = events.EvStatus,
                SelectedTypeValue     = events.EvType,
                SelectedSizeValue     = events.EvSize,
                SelectedGroupValue    = events.EvGroupId,
                SelectedAgencyValue   = events.EvAgencyId,
                EventLocations        = HlpView.GetLocations(events.EventId),
                Docs = HlpView.LstDocsOfEvent(events.EventId)
            };

            return(View(viewModel));
        }
Ejemplo n.º 15
0
        public ActionResult AddEvent()
        {
            var eventTypes = _eventTypeService.GetEventTypes();
            var viewModel  = EditEventViewModel.Build(eventTypes);

            ViewBag.EditType = "Add";

            return(View("EditEvent", viewModel));
        }
Ejemplo n.º 16
0
 public IActionResult Edit([FromForm] EditEventViewModel model)
 {
     if (!ModelState.IsValid)
     {
         return(this.View(model));
     }
     eventService.EditEvent(model);
     return(RedirectToAction(GlobalConstants.AllEventsActionString));
 }
Ejemplo n.º 17
0
        public IActionResult Create()
        {
            var model = new EditEventViewModel();

            model.StartOn = DateTime.Now;
            model.EndOn   = DateTime.Now.AddDays(1);

            return(View(model));
        }
Ejemplo n.º 18
0
        public ActionResult EditEvent(int olympicEventId)
        {
            var olympicEvent = _eventService.GetOlympicEventById(olympicEventId);
            var eventTypes   = _eventTypeService.GetEventTypes();
            var viewModel    = EditEventViewModel.Build(olympicEvent, eventTypes);

            ViewBag.EditType = "Edit";

            return(View(viewModel));
        }
Ejemplo n.º 19
0
        public ActionResult Create()
        {
            var viewModel = new EditEventViewModel
            {
                Date       = DateTime.Now,
                RoomNumber = 1
            };

            return(View(viewModel));
        }
Ejemplo n.º 20
0
        public ActionResult Create(EditEventViewModel events, HttpPostedFileBase img,
                                   List <string> lstLoc)
        {
            if (ModelState.IsValid)
            {
                //return View(events);

                try
                {
                    int    locations  = 0;
                    string targetPath = string.Empty;
                    if (lstLoc != null) //location(s) selected
                    {
                        foreach (string item in lstLoc)
                        {
                            locations += Convert.ToInt16(item);
                        }
                    }
                    ////save data
                    events.CEvents.EvStatus   = events.SelectedStatusValue;
                    events.CEvents.EvLocation = locations;
                    events.CEvents.EvType     = events.SelectedTypeValue;
                    events.CEvents.EvSize     = events.SelectedSizeValue;
                    events.CEvents.EvGroupId  = events.SelectedGroupValue;
                    events.CEvents.EvAgencyId = events.SelectedAgencyValue;
                    events.CEvents.EvUserId   = WebSecurity.GetUserId(User.Identity.Name);
                    db.Events.AddObject(events.CEvents);
                    db.SaveChanges();
                    if (img != null)
                    {
                        //read height & width from web.config
                        int imgWidth  = Convert.ToInt16(ConfigurationManager.AppSettings["EventImgWidth"]);
                        int imgHeight = Convert.ToInt16(ConfigurationManager.AppSettings["EventImgHeight"]);
                        //save image & update image path-property in model
                        targetPath = Server.MapPath("~/Images/Events/" + events.CEvents.EventId + ".jpg");
                        Image sourceImg = Image.FromStream(img.InputStream);
                        // see http://www.codeproject.com/Articles/191424/Resizing-an-Image-On-The-Fly-using-NET
                        Image resized = HlpView.ResizeImage(sourceImg, new Size(imgWidth, imgHeight));
                        resized.Save(targetPath, ImageFormat.Jpeg);
                        Events Event = db.Events.Single(d => d.EventId == events.CEvents.EventId);
                        Event.EvImgPath1 = targetPath;
                        db.ObjectStateManager.ChangeObjectState(Event, EntityState.Modified);
                        db.SaveChanges();
                    }
                    TempData["Success"] = "Der Event wurde erstellt";
                    return(RedirectToAction("Index"));
                }
                catch (Exception ex)
                {
                    TempData["Success"] = "Fehler beim Erstellen: " + ex.Message;
                    return(RedirectToAction("Index"));
                }
            }
            return(View(events));
        }
Ejemplo n.º 21
0
        // GET: Events/Edit/5
        public async Task <IActionResult> Edit(int?id)
        {
            //instantiaite view model
            EditEventViewModel vm = new EditEventViewModel();

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

            vm.Event = await _context.Events.FindAsync(id);

            if (vm.Event == null)
            {
                return(NotFound());
            }
            //set up drop down to display and select venue names

            vm.Venues = _context.Venues.Select(v => new SelectListItem
            {
                Value = v.Id.ToString(),
                Text  = v.VenueName
            }).ToList();

            vm.Venues.Insert(0, new SelectListItem()
            {
                Value = "0",
                Text  = "Please choose a venue"
            });
            vm.Vendors = _context.Vendors.Select(v => new SelectListItem
            {
                Value = v.Id.ToString(),
                Text  = v.VendorName
            }).ToList();

            vm.Vendors.Insert(0, new SelectListItem()
            {
                Value = "0",
                Text  = "Please choose a vendor"
            });
            vm.Customers = _context.Customers.Select(c => new SelectListItem
            {
                Value = c.Id.ToString(),
                Text  = c.FirstName + " " + c.LastName
            }).ToList();

            vm.Customers.Insert(0, new SelectListItem()
            {
                Value = "0",
                Text  = "Please choose a customer"
            });

            return(View(vm));
        }
Ejemplo n.º 22
0
        private string GetEventCategoryNamesCSV(EditEventViewModel model)
        {
            var selectedIds = model.SelectedEventCategoryIds.Split(',');
            var values      = selectedIds.Select(
                selectedId => model.Categories.Where(x => x.Identifier == selectedId)
                .Select(y => y.Name)
                .FirstOrDefault()
                ).ToList();

            return(string.Join(",", values));
        }
Ejemplo n.º 23
0
        public ActionResult EditEvent(int id)
        {
            EditEventViewModel model = new EditEventViewModel();

            model.AllGroups      = _groupService.GetAllGroups();
            model.AllSnippets    = _snippetService.GetAllSnippets(1, 20);
            model.AllOperations  = _snippetService.GetAllOperations();
            model.Event          = _eventService.GetEventById(id);
            model.Event.Snippets = model.Event.EventSnippets.OrderBy(x => x.OrderNumber).Select(x => x.Snippet).ToList();

            return(View(model));
        }
Ejemplo n.º 24
0
        public ActionResult Edit(int id, string category, string type, int eventId = -1)
        {
            if (!Services.Authorizer.Authorize(StandardPermissions.SiteOwner, T("Not authorized to manage rules")))
            {
                return(new HttpUnauthorizedResult());
            }

            var ev = _rulesManager.DescribeEvents().SelectMany(x => x.Descriptors).Where(x => x.Category == category && x.Type == type).FirstOrDefault();

            if (ev == null)
            {
                return(HttpNotFound());
            }

            // if there is no form to edit, save the action and go back to the rule
            if (ev.Form == null)
            {
                if (eventId == -1)
                {
                    var rule = _rulesServices.GetRule(id);
                    rule.Events.Add(new EventRecord {
                        Category = category, Type = type
                    });
                }

                return(RedirectToAction("Edit", "Admin", new { id }));
            }

            // build the form, and let external components alter it
            var form = _formManager.Build(ev.Form);

            // generate an anti forgery token
            AddSubmitButton(form);

            // bind form with existing values).
            if (eventId != -1)
            {
                var rule        = _rulesServices.GetRule(id);
                var eventRecord = rule.Events.Where(a => a.Id == eventId).FirstOrDefault();
                if (eventRecord != null)
                {
                    var parameters = FormParametersHelper.FromString(eventRecord.Parameters);
                    _formManager.Bind(form, new DictionaryValueProvider <string>(parameters, CultureInfo.InvariantCulture));
                }
            }

            var viewModel = new EditEventViewModel {
                Id = id, Event = ev, Form = form
            };

            return(View(viewModel));
        }
Ejemplo n.º 25
0
        public async Task <IActionResult> EditEvent(string eventID)
        {
            UserEvent originalUserEvent = await userEventRepository.GetEventByID(eventID);

            EditEventViewModel model = new EditEventViewModel
            {
                EventID      = eventID,
                WorkingDayID = originalUserEvent.WorkingDayID,
                Time         = originalUserEvent.Time,
                Event        = originalUserEvent.Event
            };

            return(View(model));
        }
Ejemplo n.º 26
0
        //
        // GET: /KultiEvents/Create
        public ActionResult Create()
        {
            var events    = new Events();
            var viewModel = new EditEventViewModel
            {
                Status         = HlpView.Status,
                Type           = HlpView.EventType,
                Group          = HlpView.Group,
                Size           = HlpView.EventSize,
                Agency         = HlpView.Agency,
                EventLocations = HlpView.GetLocations(0) //return all locations as false
            };

            return(View(viewModel));
        }
Ejemplo n.º 27
0
        private void SetLogo(EditEventViewModel viewModel, ModelStateDictionary modelState)
        {
            bool hasLogo = Session[CurrentLogoKey] != null;

            if (hasLogo)
            {
                viewModel.Logo         = (byte[])Session[CurrentLogoKey];
                viewModel.IsLogoSetted = true;
                viewModel.HasLogo      = true;
                if (modelState.ContainsKey("HasLogo"))
                {
                    modelState.Remove("HasLogo");
                }
            }
        }
Ejemplo n.º 28
0
        public async Task <IActionResult> Create()
        {
            if (!(await _authorizationService.AuthorizeAsync(User, Policies.Admin)).Succeeded)
            {
                return(Forbid());
            }

            var model = new EditEventViewModel();

            model.StartOn   = DateTime.Now.Date;
            model.EndOn     = DateTime.Now.Date.AddDays(1);
            model.DisplayOn = DateTime.Now.Date;

            return(View(model));
        }
Ejemplo n.º 29
0
        public ActionResult Edit(MyEventsIdentity identity, int eventDefinitionId)
        {
            EventDefinition eventDefinition = _eventsRepository.GetById(eventDefinitionId);

            _authorizationService.ValidateEventAuthorization(identity, eventDefinition);

            var viewModel = new EditEventViewModel()
            {
                HasLogo = true
            };

            MapEventDefinitionToViewModel(eventDefinition, viewModel);
            ResetLogo();
            return(View(viewModel));
        }
Ejemplo n.º 30
0
        public async Task UpdateAsync(EditEventViewModel input)
        {
            var eventToUpdate = this.eventsRepository
                                .All()
                                .Where(x => x.Id == input.Id)
                                .FirstOrDefault();

            eventToUpdate.Title        = input.Title;
            eventToUpdate.TransportId  = input.TransportId;
            eventToUpdate.StartTime    = DateTime.Parse(input.StartTime);
            eventToUpdate.EndTime      = DateTime.Parse(input.EndTime);
            eventToUpdate.Details      = input.Details;
            eventToUpdate.MaxGroupSize = input.MaxGroupSize;

            await this.eventsRepository.SaveChangesAsync();
        }