public async Task <IActionResult> Create([Bind("Id,Name,Summary,Text,DateBegin,DateEnd,Duration,Image,FormFile")] Event @event) { if (ModelState.IsValid) { _context.Add(@event); await _context.SaveChangesAsync(); if (@event.FormFile != null) { var newImageName = @event.Id.ToString() + Path.GetExtension(@event.FormFile.FileName); @event.Image = newImageName; _context.Update(@event); await _context.SaveChangesAsync(); } if (@event.FormFile != null) { // full path to file in temp location var filePath = Path.GetTempFileName(); var uploads = Path.Combine(_hostingEnvironment.WebRootPath, "img/events"); var fullPath = Path.Combine(uploads, @event.Image); if (!Directory.Exists(fullPath)) { @event.FormFile.CopyTo(new FileStream(fullPath, FileMode.Create)); } } return(RedirectToAction(nameof(Index))); } return(View(@event)); }
public async Task <IActionResult> Edit(int id, [Bind("Id,Forename,Surname,DateOfBirth, Image")] Client client) { if (id != client.Id) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(client); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!ClientExists(client.Id)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(client)); }
public async Task <IActionResult> Edit(int id, [Bind("Id,Year,Week,Day,GroupId,EmployeeId,StartTime,EndTime")] DutyRoster dutyRoster) { if (id != dutyRoster.Id) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(dutyRoster); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!DutyRosterExists(dutyRoster.Id)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(dutyRoster)); }
public async Task <IActionResult> Edit(int id, [Bind("Id,Name,GroupLeaderEmployeeId,Image")] Group @group) { if (id != @group.Id) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(@group); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!GroupExists(@group.Id)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(@group)); }
public async Task <IActionResult> Edit(int id, [Bind("Id,Forename,Surname,Image, GroupId")] Employee employee) { if (id != employee.Id) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(employee); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!EmployeeExists(employee.Id)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(employee)); }
public async Task <IActionResult> Edit(int id, [Bind("Id,EventId,ApplicationUserId")] EventMember eventMember) { if (id != eventMember.Id) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(eventMember); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!EventMemberExists(eventMember.Id)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(eventMember)); }
public async Task <IActionResult> Create([Bind("EventDetailId,EventId,Title,Text,Image,FormFile")] EventDetails eventDetails) { if (ModelState.IsValid) { eventDetails.DateCreate = DateTime.Now; eventDetails.ApplicationUserId = _userManager.GetUserId(User); eventDetails.ApplicationUser = await _userManager.GetUserAsync(User); _context.Add(eventDetails); await _context.SaveChangesAsync(); if (eventDetails.FormFile != null) { var newImageName = Path.Combine(eventDetails.EventDetailId.ToString(), Path.GetExtension(eventDetails.FormFile.FileName)); eventDetails.Image = newImageName; _context.Update(eventDetails); await _context.SaveChangesAsync(); // full path to file in temp location var filePath = Path.GetTempFileName(); var uploadsFolder = Path.Combine(_hostingEnvironment.WebRootPath, "img/event-details"); if (!Directory.Exists(uploadsFolder)) { Directory.CreateDirectory(uploadsFolder); } var fullPath = Path.Combine(uploadsFolder, eventDetails.Image); if (!Directory.Exists(fullPath)) { eventDetails.FormFile.CopyTo(new FileStream(fullPath, FileMode.Create)); } } return(RedirectToAction(nameof(Index))); } ViewData["EventId"] = new SelectList(_context.Events, "Id", "Name", eventDetails.EventId); return(View(eventDetails)); }