Ejemplo n.º 1
0
        public IActionResult Delete(int id)
        {
            User usersData = _userRepository.GetSingle(id);

            if (usersData == null)
            {
                return(new NotFoundResult());
            }
            else
            {
                IEnumerable <Participants>   participants   = _participantsRepository.FindBy(e => e.UserId == id);
                IEnumerable <MeetingSchemas> meetingSchemas = _meetingSchemasRepository.FindBy(e => e.CreatorId == id);

                foreach (var participant in participants)
                {
                    _participantsRepository.Delete(participant);
                }

                foreach (var meetingSchmema in meetingSchemas)
                {
                    _participantsRepository.DeleteWhere(e => e.MeetingSchemaId == meetingSchmema.Id);
                    _meetingSchemasRepository.Delete(meetingSchmema);
                }
                _userRepository.Delete(usersData);

                return(new NoContentResult());
            }
        }
Ejemplo n.º 2
0
        public IActionResult Put(int id, [FromBody] MeetingSchemaViewModel meetingSchemaViewModel)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            MeetingSchemas _meetingSchemas = _meetingSchemasRepository.GetSingle(id);

            if (_meetingSchemas == null)
            {
                return(NotFound());
            }
            else
            {
                _meetingSchemas.Title       = meetingSchemaViewModel.Title;
                _meetingSchemas.Location    = meetingSchemaViewModel.Location;
                _meetingSchemas.Description = meetingSchemaViewModel.Description;
                _meetingSchemas.Status      = (MeetingSchemaStatus)Enum.Parse(typeof(MeetingSchemaStatus), meetingSchemaViewModel.Status);
                _meetingSchemas.Type        = (MeetingSchemaType)Enum.Parse(typeof(MeetingSchemaType), meetingSchemaViewModel.Type);
                _meetingSchemas.TimeStart   = meetingSchemaViewModel.TimeStart;
                _meetingSchemas.TimeEnd     = meetingSchemaViewModel.TimeEnd;

                _participantsRepository.DeleteWhere(e => e.MeetingSchemaId == id);

                foreach (var user_id in meetingSchemaViewModel.Participants)
                {
                    _meetingSchemas.Participants.Add(new Participants {
                        MeetingSchemaId = id, UserId = id
                    });
                }

                _meetingSchemasRepository.Commit();
            }

            //Mapp to ViewModel from DB
            meetingSchemaViewModel = Mapper.Map <MeetingSchemas, MeetingSchemaViewModel>(_meetingSchemas);

            return(new NoContentResult());
        }