예제 #1
0
        public void EditDetention(Detention detention)
        {
            prisonerDataService.EditDetention(detention);

            var cacheKey = $"Detention_{detention.DetentionID}";

            HttpRuntime.Cache.Remove(cacheKey);
        }
예제 #2
0
        public async Task CreateDetention(params CreateDetentionRequest[] detentionModels)
        {
            using (var unitOfWork = await DataConnectionFactory.CreateUnitOfWork())
            {
                foreach (var model in detentionModels)
                {
                    var detention = new Detention
                    {
                        DetentionTypeId = model.DetentionTypeId,
                        SupervisorId    = model.SupervisorId,
                        Event           = new DiaryEvent
                        {
                            StartTime   = model.StartTime,
                            EndTime     = model.EndTime,
                            RoomId      = model.RoomId,
                            EventTypeId = EventTypes.Detention,
                            Subject     = "Detention"
                        }
                    };

                    unitOfWork.Detentions.Create(detention);


                    DateTime?nextOccurrence = model.StartTime.GetNextOccurrence(model.Frequency);
                    TimeSpan duration       = model.EndTime - model.StartTime;

                    while (nextOccurrence != null && nextOccurrence.Value < model.LastOccurrence)
                    {
                        var nextDetention = new Detention
                        {
                            DetentionTypeId = model.DetentionTypeId,
                            SupervisorId    = model.SameSupervisor ? model.SupervisorId : null,
                            Event           = new DiaryEvent
                            {
                                StartTime   = nextOccurrence.Value,
                                EndTime     = nextOccurrence.Value.Add(duration),
                                RoomId      = model.RoomId,
                                EventTypeId = EventTypes.Detention,
                                Subject     = "Detention"
                            }
                        };

                        unitOfWork.Detentions.Create(nextDetention);
                        await unitOfWork.BatchSaveChangesAsync();

                        nextOccurrence = nextOccurrence.Value.GetNextOccurrence(model.Frequency);
                    }
                }

                await unitOfWork.SaveChangesAsync();
            }
        }
예제 #3
0
        public IHttpActionResult InsertDetention([FromBody] Detention detention)
        {
            if (!ModelState.IsValid)
            {
                CustomLogging.LogMessage(CustomLogging.TracingLevel.INFO, CustomLogging.ModelStatusConverter(ModelState));
                return(BadRequest(ModelState));
            }

            if (_employeeService.GetEmployeeByID(detention.DetainedByEmployeeID) == null)
            {
                CustomLogging.LogMessage(CustomLogging.TracingLevel.INFO, "Не такого сотрудника");
                return(BadRequest("Нет сотрудника"));
            }

            _detentionService.InsertDetention(detention);
            detention.DetentionID = _detentionService.LastDetention();
            return(Ok(detention));
        }
        public void InsertDetention(Detention detention)
        {
            const string storedProcedureName = Constants.InsertDetention;

            using (SqlConnection connection = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["DBConnection"].ConnectionString))
            {
                SqlCommand command = new SqlCommand(storedProcedureName, connection);
                command.CommandType = CommandType.StoredProcedure;

                command.Parameters.Add(Constants.DetentionDate, SqlDbType.DateTime);
                command.Parameters[Constants.DetentionDate].Value = detention.DetentionDate;

                command.Parameters.Add(Constants.DetainedByEmployeeID, SqlDbType.Int);
                command.Parameters[Constants.DetainedByEmployeeID].Value = detention.DetainedByEmployeeID;

                connection.Open();
                command.ExecuteNonQuery();
                connection.Close();
            }
        }
        public List <Detention> GetDetentionsByLastName(string lastname)
        {
            const string storedProcedureName = Constants.GetDetentionsByLastName;

            using (SqlConnection connection = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["DBConnection"].ConnectionString))
            {
                SqlCommand command = new SqlCommand(storedProcedureName, connection);
                command.CommandType = CommandType.StoredProcedure;
                connection.Open();

                command.Parameters.Add(Constants.LastName, SqlDbType.NVarChar);
                command.Parameters[Constants.LastName].Value = lastname;

                SqlDataReader reader    = command.ExecuteReader();
                Detention     detention = null;

                List <Detention> detentions_list = new List <Detention>();
                while (reader.Read())
                {
                    detention = new Detention
                    {
                        DetentionID = Convert.ToInt32(reader.GetValue(0))
                    };

                    if (reader.GetValue(1) == DBNull.Value)
                    {
                        detention.DetentionDate = null;
                    }
                    else
                    {
                        detention.DetentionDate = Convert.ToDateTime(reader.GetValue(1));
                    }

                    detention.DetainedByEmployeeID = Convert.ToInt32(reader.GetValue(2));

                    detentions_list.Add(detention);
                }
                connection.Close();
                return(detentions_list);
            }
        }
예제 #6
0
        public IHttpActionResult UpdateDetention(int id, [FromBody] Detention detention)
        {
            if (!ModelState.IsValid)
            {
                CustomLogging.LogMessage(CustomLogging.TracingLevel.INFO, CustomLogging.ModelStatusConverter(ModelState));
                return(BadRequest(ModelState));
            }
            if (_detentionService.GetDetentionByID(id) == null)
            {
                CustomLogging.LogMessage(CustomLogging.TracingLevel.INFO, "Нет такого задержания");
                return(NotFound());
            }
            if (_employeeService.GetEmployeeByID(detention.DetainedByEmployeeID) == null)
            {
                CustomLogging.LogMessage(CustomLogging.TracingLevel.INFO, "Нет такого сотрудника");
                return(BadRequest("Нет сотрудника"));
            }

            _detentionService.UpdateDetention(id, detention);
            return(Ok(detention));
        }
예제 #7
0
        private void LoadFromModel(Detention model)
        {
            DetentionTypeId = model.DetentionTypeId;
            EventId         = model.EventId;
            SupervisorId    = model.SupervisorId;

            if (model.Type != null)
            {
                Type = new DetentionTypeModel(model.Type);
            }

            if (model.Event != null)
            {
                Event = new DiaryEventModel(model.Event);
            }

            if (model.Supervisor != null)
            {
                Supervisor = new StaffMemberModel(model.Supervisor);
            }
        }
예제 #8
0
        public async Task Create(params CreateDetentionRequest[] detentionModels)
        {
            foreach (var model in detentionModels)
            {
                var detention = new Detention
                {
                    DetentionTypeId = model.DetentionTypeId,
                    SupervisorId    = model.SupervisorId,
                    Event           = new DiaryEvent
                    {
                        StartTime   = model.StartTime,
                        EndTime     = model.EndTime,
                        RoomId      = model.RoomId,
                        EventTypeId = EventTypes.Detention,
                        Subject     = "Detention"
                    }
                };

                _detentionRepository.Create(detention);
            }

            await _detentionRepository.SaveChanges();
        }
        public Detention GetDetentionByID(int id)
        {
            const string storedProcedureName = Constants.GetDetentionByID;

            using (SqlConnection connection = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["DBConnection"].ConnectionString))
            {
                SqlCommand command = new SqlCommand(storedProcedureName, connection);
                command.CommandType = CommandType.StoredProcedure;

                command.Parameters.Add(Constants.DetentionID, SqlDbType.Int);
                command.Parameters[Constants.DetentionID].Value = id;

                connection.Open();
                SqlDataReader reader = command.ExecuteReader();

                Detention detention = null;
                while (reader.Read())
                {
                    detention = new Detention();

                    detention.DetentionID = Convert.ToInt32(reader.GetValue(0));

                    if (reader.GetValue(1) == DBNull.Value)
                    {
                        detention.DetentionDate = null;
                    }
                    else
                    {
                        detention.DetentionDate = Convert.ToDateTime(reader.GetValue(1));
                    }

                    detention.DetainedByEmployeeID = Convert.ToInt32(reader.GetValue(2));
                }
                connection.Close();
                return(detention);
            }
        }
예제 #10
0
        public void EditDetention(DetentionDto detention)
        {
            if (detention != null)
            {
                var detentionEntity = new Detention()
                {
                    DetentionID      = detention.DetentionID,
                    AccruedAmount    = detention.AccruedAmount ?? default(decimal),
                    PaidAmount       = detention.PaidAmount ?? default(decimal),
                    DateOfArrival    = detention.DateOfArrival,
                    DateOfDetention  = detention.DateOfDetention,
                    DateOfRelease    = detention.DateOfRelease,
                    PlaceofDetention = detention.PlaceofDetention
                };
                dataService.ExecNonQuery("EditDetention", detentionEntity);

                dataService.ExecNonQuery("EditEmployee", detention.DeliveredEmployee);
                dataService.ExecNonQuery("EditEmployee", detention.DetainedEmployee);
                if (detention.ReleasedEmployee != null)
                {
                    dataService.ExecNonQuery("EditEmployee", detention.ReleasedEmployee);
                }
            }
        }
예제 #11
0
        public void EditDetention(Detention detention)
        {
            var detentionDto = Mapper.Map <Detention, DetentionDto>(detention);

            prisonerClient.EditDetention(detentionDto);
        }
예제 #12
0
 public void UpdateDetention(int id, Detention detention)
 {
     _detentionDataProvider.UpdateDetention(id, detention);
 }
예제 #13
0
 public void InsertDetention(Detention detention)
 {
     _detentionDataProvider.InsertDetention(detention);
 }
예제 #14
0
 public DetentionModel(Detention model) : base(model)
 {
     LoadFromModel(model);
 }