public void AddUserToVMContext(InputModel user)
        {
            VacationManagerContext _context = new VacationManagerContext();

            _context.Users.Add(new User
            {
                UserName  = user.Email,
                Password  = user.Password,
                FirstName = Input.FirstName,
                LastName  = Input.LirstName
            });
            _context.SaveChanges();
        }
Exemplo n.º 2
0
        protected override void DataPortal_Execute()
        {
            using (var ctx = new VacationManagerContext())
            {
                var request = ctx.Requests.FirstOrDefault(x => x.Id == _requestNumber);
                if (request == null)
                {
                    throw new ApplicationException(string.Format(
                                                       "Request number {0} was not found. It must exist in order to change it's state.", _requestNumber));
                }

                request.State = _state;
                ctx.SaveChanges();
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// Remove service object having parameter id. For the moment we assume this
        /// means to cancel a submitted request.
        /// </summary>
        protected void DataPortal_Delete(long id)
        {
            using (var ctx = new VacationManagerContext())
            {
                var request = ctx.Requests.FirstOrDefault(x => x.Id == id);
                if (request == null)
                {
                    throw new ApplicationException(string.Format(
                                                       "Request number {0} was not found. It must exist in order to be deleted.", id));
                }

                if (request.State != VacationRequestState.Submitted)
                {
                    throw new ApplicationException(string.Format(
                                                       "Request {0} was already {1}, cannot be deleted anymore. It must be in submited state in order to be deleted.",
                                                       id, request.State));
                }

                ctx.Requests.Remove(request);
                ctx.SaveChanges();
            }
        }
Exemplo n.º 4
0
        /// <summary>
        /// Create new service object and persist it. For the moment we assume this
        /// means to submit a new vacation request.
        /// </summary>
        protected override void DataPortal_Insert()
        {
            using (var ctx = new VacationManagerContext())
            {
                var employee = ctx.Employees.FirstOrDefault(x => x.Id == EmployeeId);
                if (employee == null)
                {
                    throw new ApplicationException(
                              string.Format("New request is associated with inexistent employee having id {0}.", EmployeeId));
                }

                var numberOfVacationDaysLeft = ctx.Situations.Single(x => x.Employee.Id == EmployeeId).AvailableDays;
                if ((NumberOfDays < 1) || (NumberOfDays > numberOfVacationDaysLeft))
                {
                    throw new ApplicationException(
                              string.Format("New request has invalid number of vacation days {0}. Must greather than 0 and less or equal than days left {1}.", NumberOfDays, NumberOfDays));
                }

                var request = new Persistence.Model.VacationRequestEntity
                {
                    CreationDate = DateTime.Now, // TODO: utc?
                    StartDate    = StartDate,
                    EndDate      = EndDate,
                    State        = VacationRequestState.Submitted,
                    Employee     = employee,
                };

                ctx.Requests.Add(request);
                ctx.SaveChanges();

                _requestNumber    = request.Id;
                _submissionDate   = request.CreationDate;
                _stateId          = request.State;
                _employeeFullName = employee.Firstname + " " + employee.LastName;
            }
        }
        public void Can_insert_an_Employee_record_without_a_situation()
        {
            var employee = BuildEmployee();

            _ctx.Employees.Add(employee);
            _ctx.SaveChanges();

            Assert.IsNotNull(_ctx.Employees.Find(employee.Id));
        }