public Minute Add(Minute minute)
        {
            MM_Minute minuteDbModel = new MM_Minute()
            {
                Title       = minute.Title,
                AgendaId    = minute.Agenda.Id,
                CreatedBy   = minute.UserCreated.Id,
                CreatedDate = DateTime.UtcNow,
                ModifiedBy  = null,
            };

            _meetingDbContext.MM_Minutes.Add(minuteDbModel);

            try
            {
                _meetingDbContext.SaveChanges();
            }
            catch (DbEntityValidationException e)
            {
                foreach (var eve in e.EntityValidationErrors)
                {
                    Console.WriteLine("Entity of type \"{0}\" in state \"{1}\" has the following validation errors:",
                                      eve.Entry.Entity.GetType().Name, eve.Entry.State);
                    foreach (var ve in eve.ValidationErrors)
                    {
                        Console.WriteLine("- Property: \"{0}\", Error: \"{1}\"",
                                          ve.PropertyName, ve.ErrorMessage);
                    }
                }
                //throw new AddFailedException<Minute>();
            }

            return(null);
        }
        public Minute GetById(int id)
        {
            MM_Minute minuteDbModel = _meetingDbContext.MM_Minutes.FirstOrDefault(r => r.Id == id);

            if (minuteDbModel == null)
            {
                throw new EntityNotFoundException <Minute>(id);
            }

            return(minuteDbModel.ConvertToMinutes());
        }
        public Minute GetByAgendaId(int id)
        {
            MM_Minute minuteDbModel = _meetingDbContext.MM_Minutes.FirstOrDefault(m => m.AgendaId == id);

            //if (minuteDbModel == null)
            //    throw new EntityNotFoundException<Minute>(id);

            if (minuteDbModel == null)
            {
                return(null);
            }
            return(minuteDbModel.ConvertToMinutes());
        }
Ejemplo n.º 4
0
 public static Minute ConvertToMinutes(this MM_Minute minuteDbModel)
 {
     return(new Minute()
     {
         Id = minuteDbModel.Id,
         Title = minuteDbModel.Title,
         //Agenda = minuteDbModel.MM_Agenda.ConvertToAgendas(),
         UserCreated = minuteDbModel.MM_User.ConvertToUser(),
         CreatedDate = minuteDbModel.CreatedDate,
         UserModified = minuteDbModel.ModifiedBy == null ? null : new User()
         {
             Id = (int)minuteDbModel.MM_User.Id
         },
         ModifiedDate = minuteDbModel.ModifiedDate
     });
 }
        public void Delete(int id)
        {
            MM_Minute minuteDbModel = _meetingDbContext.MM_Minutes.FirstOrDefault(x => x.Id == id);

            if (minuteDbModel == null)
            {
                throw new EntityNotFoundException <MeetingLocation>(id);
            }

            _meetingDbContext.MM_Minutes.Remove(minuteDbModel);

            try
            {
                _meetingDbContext.SaveChanges();
            }
            catch (Exception ex)
            {
                throw new DeleteFailedException <Minute>(id);
            }
        }
        public void Update(Minute minute)
        {
            MM_Minute minuteDbModel = _meetingDbContext.MM_Minutes.Find(minute.Id);

            if (minuteDbModel == null)
            {
                throw new EntityNotFoundException <Minute>((int)minute.Id);
            }

            minuteDbModel.Title        = minute.Title;
            minuteDbModel.ModifiedBy   = minute.UserCreated.Id;
            minuteDbModel.ModifiedDate = DateTime.UtcNow;

            try
            {
                _meetingDbContext.SaveChanges();
            }
            catch (Exception ex)
            {
                throw new UpdateFailedException <Minute>();
            }
        }