Exemplo n.º 1
0
        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));
        }
Exemplo n.º 2
0
        public async Task <IActionResult> Create([Bind("Id,Forename,Surname,DateOfBirth,Image")] Client client)
        {
            if (ModelState.IsValid)
            {
                _context.Add(client);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(client));
        }
Exemplo n.º 3
0
        public async Task <IActionResult> Create([Bind("Id,Year,Week,Day,GroupId,EmployeeId,StartTime,EndTime")] DutyRoster dutyRoster)
        {
            if (ModelState.IsValid)
            {
                _context.Add(dutyRoster);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(dutyRoster));
        }
        public async Task <IActionResult> Create([Bind("Id,Name,GroupLeaderEmployeeId,Image,GroupId")] Group @group)
        {
            if (ModelState.IsValid)
            {
                _context.Add(@group);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(@group));
        }
Exemplo n.º 5
0
        public async Task <IActionResult> Create([Bind("Id,Forename,Surname,Image, GroupId")] Employee employee)
        {
            if (ModelState.IsValid)
            {
                _context.Add(employee);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(employee));
        }
Exemplo n.º 6
0
        public async Task <IActionResult> Create(EventMember eventMember)
        {
            //if (ModelState.IsValid)
            //{
            //}

            var eventMembers = from e in _context.EventMembers
                               where e.EventId == eventMember.EventId && e.ApplicationUserId == eventMember.ApplicationUserId
                               select e;

            if (eventMembers.Count() == 0)
            {
                _context.Add(eventMember);
                await _context.SaveChangesAsync();
            }

            return(Redirect("/Privacy"));
            // return RedirectToAction(nameof(Index));

            //return View(eventMember);
        }
Exemplo n.º 7
0
        private async Task <InstitutionController> GetInstitutionController(string name, Institution institution)
        {
            var options = new DbContextOptionsBuilder <InstitutionContext>()
                          .UseInMemoryDatabase(databaseName: name)
                          .Options;
            var context = new InstitutionContext(options);

            context.Institutions.Add(institution);
            await context.SaveChangesAsync();

            var controller = new InstitutionController(context);

            return(controller);
        }
Exemplo n.º 8
0
        public async Task <ActionResult <Institution> > PostMember(Institution institution)
        {
            if (ModelState.IsValid)
            {
                _context.Institutions.Add(institution);
                await _context.SaveChangesAsync();

                return(CreatedAtAction("GetInstitutions", new { id = institution.InstitutionId }, institution));
            }
            else
            {
                return(Json(new { status = "error", message = "error creating customer" }));
            }
        }
Exemplo n.º 9
0
        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));
        }