public async Task <IActionResult> Create([Bind("LastName,FirstName,BirthDate,NextScheduledDate")] Patient patient)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    _context.Add(patient);
                    await _context.SaveChangesAsync();

                    return(RedirectToAction(nameof(Index)));
                }
            }
            catch (DbUpdateException)
            {
                ModelState.AddModelError("", "Incapaz de salvar as alterações. " +
                                         "Tente novamente e se o problema persistir" +
                                         "consulte o administrador do sistema.");
            }
            return(View(patient));
        }
        public async Task <IActionResult> CreateEvent([FromBody] EventDto eventDto)
        {
            if (eventDto.Type == EventType.EXCLUSIVE &&
                _scheduleContext.Event.Any(a => a.Type == EventType.EXCLUSIVE && a.Date == eventDto.Date))
            {
                return(Conflict("Exclusive events on the same date."));
            }

            Event @event = new Event(eventDto.Name,
                                     eventDto.Type,
                                     eventDto.Date,
                                     eventDto.Local,
                                     eventDto.Participants,
                                     eventDto.Status

                                     );

            _scheduleContext.Add(@event);
            await _scheduleContext.SaveChangesAsync();

            return(Ok(@event));
        }
Exemple #3
0
        public async Task <IActionResult> Create(Employee employee, string[] selectedServices)
        {
            if (selectedServices != null)
            {
                employee.ServiceAssignments = new List <ServiceAssignment>();
                foreach (var service in selectedServices)
                {
                    var serviceToAdd = new ServiceAssignment {
                        EmployeeID = employee.ID, ServiceID = int.Parse(service)
                    };
                    employee.ServiceAssignments.Add(serviceToAdd);
                }
            }
            if (ModelState.IsValid)
            {
                _context.Add(employee);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            PopulateAssignedServiceData(employee);
            return(View(employee));
        }
Exemple #4
0
 public void Add(Schedule schedule)
 {
     _dbContext.Add(schedule);
     Save();
 }
        public async Task <IActionResult> Broadcast([Bind("Id,UserId,CurrentShiftId,RequestCreatedDate,PendingSwitches")] SwitchRequest vm)
        {
            var user = await _context.User.SingleOrDefaultAsync(m => m.Id == vm.UserId);

            if (user == null)
            {
                user = _context.User.SingleOrDefault(s => s.Email.Equals(User.Identity.Name));
                if (user == null)
                {
                    ModelState.AddModelError("NotFound", "User with given ID doesn't exist.");
                }
            }

            var currentShift = await _context.Shift.SingleOrDefaultAsync(m => m.Id == vm.CurrentShiftId);

            if (currentShift == null)
            {
                ModelState.AddModelError("NotFound", "Current shift with given ID doesn't exist.");
            }

            // Add N pending switch to notify all users about your current-shift-date switch request
            var pendingSwitches = await _context.PendingSwitch.Where(m => m.SwitchRequestId == vm.Id).ToListAsync();

            //if (pendingSwitches.Any())
            var users = _context.User.Where(u => u.Email != user.Email && u.IsActive).ToList();

            foreach (var u in users)
            {
                var pendingSwitch = new PendingSwitch();
                pendingSwitch.UserId = u.Id; // for each valid users
                pendingSwitch.Date   = currentShift?.ShiftDate;
                pendingSwitch.Status = ScheduleApp.Web.Extensions.Constants.REQUEST_STATUS_NEW;

                pendingSwitches.Add(pendingSwitch);
            }

            //if (ModelState.IsValid)
            //{
            //    _context.Add(pendingSwitch);
            //    await _context.SaveChangesAsync();
            //}

            var switchRequest = new SwitchRequest()
            {
                IsBroadcast        = true,
                HasBeenSwitched    = false,
                CurrentShift       = currentShift,
                User               = user,
                RequestCreatedDate = DateTime.Now
            };

            // Add N pending switch to notify all users about your current-shift-date switch request
            foreach (var pendingSwitch in pendingSwitches)
            {
                switchRequest.PendingSwitches?.Add(pendingSwitch);
            }

            if (ModelState.IsValid)
            {
                _context.Add(switchRequest);
                await _context.SaveChangesAsync();

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

            ViewData["CurrentShiftId"] = new SelectList(_context.Schedule.Include(s => s.User).Where(s => s.User.Email == User.Identity.Name).Select(s => s.Shift).OrderBy(s => s.ShiftDate), "Id", "ShiftDate", vm.CurrentShiftId);
            //ViewData["UserId"] = new SelectList(_context.User.Where(s => s.Email.Equals(User.Identity.Name)), "Id", "Email", vm.UserId);

            return(View(vm));
        }