public int UpdateEvent(EventNewViewModel newEventInfo, string username, int eventId) { int?categoryId = Context.Categories .Where(c => c.Name == newEventInfo.Category) .Select(c => c.Id) .FirstOrDefault(); if (categoryId == 0) { Category newCategory = new Category { Name = newEventInfo.Category }; Context.Categories.Add(newCategory); Context.SaveChanges(); categoryId = newCategory.Id; } var newEvent = Context.Events.Single(events => events.Id == eventId); newEvent.CreationTime = DateTime.Now; newEvent.EventBegin = newEventInfo.StartTime; newEvent.EventEnd = newEventInfo.EndTime; newEvent.Location = newEventInfo.Location; newEvent.Description = newEventInfo.Description; newEvent.Name = newEventInfo.Name; newEvent.Category_Id = categoryId.Value; newEvent.Suspended = newEventInfo.Suspended; Context.SaveChanges(); return(newEvent.Id); }
public ActionResult EditEvent(EventNewViewModel newEvent) { string userName = User.Identity.Name; int eventId = EventService.UpdateEvent(newEvent, userName, ID); return(RedirectToAction("Index", "Event", new { eventId = eventId })); }
public ActionResult Create() { EventNewViewModel newEvent = new EventNewViewModel { StartTime = DateTime.Now, EndTime = DateTime.Now }; return(View(newEvent)); }
public ActionResult EditEvent(int eventId) { ID = eventId; EventFullModel editEvent = EventService.GetEvent(eventId, User.Identity.Name); EventNewViewModel newEvent = new EventNewViewModel(); newEvent.Name = editEvent.Name; newEvent.Description = editEvent.Description; newEvent.Category = editEvent.CategoryName; newEvent.StartTime = Convert.ToDateTime(editEvent.StartDate); newEvent.EndTime = Convert.ToDateTime(editEvent.EndDate); newEvent.Location = ""; newEvent.Suspended = editEvent.Suspended; return(View(newEvent)); }
public IActionResult New(EventNewViewModel viewModel) { if (!ModelState.IsValid) { return(View(viewModel)); } string uniqueFileName = null; if (viewModel.Photos != null && viewModel.Photos.Count > 0) { foreach (IFormFile photo in viewModel.Photos) { var extension = Path.GetExtension(photo.FileName).ToLower(); if (extension == ".jpg" || extension == ".jpeg" || extension == ".png") { string uploadsFolder = Path.Combine(_hostingEnvironment.WebRootPath, "images"); uniqueFileName = Guid.NewGuid().ToString() + "_" + photo.FileName; string filePath = Path.Combine(uploadsFolder, uniqueFileName); photo.CopyTo(new FileStream(filePath, FileMode.Create)); } else { throw new Exception("Dosya türü .JPG , .JPEG veya .PNG olmalıdır.."); } } } Event newEvent = new Event() { Name = viewModel.Name, Description = viewModel.Description, Slug = viewModel.Slug, EditorContent = viewModel.EditorContent, ImageUrl = uniqueFileName, StatusId = viewModel.StatusId, Location = viewModel.Location, StartDate = viewModel.StartDate, EndDate = viewModel.EndDate, CampusId = viewModel.CampusId }; _eventService.New(newEvent); return(RedirectToAction("Index")); }
public int CreateNewEvent(EventNewViewModel newEventInfo, string username) { int?categoryId = Context.Categories .Where(c => c.Name == newEventInfo.Category) .Select(c => c.Id) .FirstOrDefault(); if (categoryId == 0) { Category newCategory = new Category { Name = newEventInfo.Category }; Context.Categories.Add(newCategory); Context.SaveChanges(); categoryId = newCategory.Id; } Event newEvent = new Event { CreationTime = DateTime.Now, EventBegin = newEventInfo.StartTime, EventEnd = newEventInfo.EndTime, Location = newEventInfo.Location, Description = newEventInfo.Description, Name = newEventInfo.Name, Category_Id = categoryId.Value }; Context.Events.Add(newEvent); Context.SaveChanges(); return(newEvent.Id); }