Ejemplo n.º 1
0
        public async Task <ObjectiveDTO> UpdateObjective(ObjectiveDTO dto)
        {
            var objective = await _context.Objectives.SingleOrDefaultAsync(x => x.Id == dto.Id);

            if (objective == null)
            {
                throw new Exception($"There is no objective with id '{dto.Id}'");
            }

            if (objective.StatusTypeKey != (int)dto.StatusType)
            {
                var history = new ObjectiveHistoryDB
                {
                    CurrentStatusTypeKey = (int)dto.StatusType,
                    IsNew                 = false,
                    ObjectiveId           = objective.Id,
                    PreviousStatusTypeKey = objective.StatusTypeKey,
                    UpdateDate            = _dateTimeWrapper.Now
                };
                _context.ObjectiveHistories.Add(history);
            }

            objective.Details        = dto.Details;
            objective.Priority       = dto.Priority;
            objective.StatusDate     = dto.StatusDate;
            objective.StatusDetails  = dto.StatusDetails;
            objective.StatusTypeKey  = (int)dto.StatusType;
            objective.Title          = dto.Title;
            objective.LastUpdateDate = _dateTimeWrapper.Now;
            _context.Objectives.Update(objective);

            await _context.SaveChangesAsync();

            return(EntityMapping.GetMapper(_mapperConfig).Map <ObjectiveDTO>(objective));
        }
        private ObjectiveHistoryDB CreateObjectiveHistory(int id, ObjectiveDB objective, bool isNew, StatusTypeDB currentStatusType, StatusTypeDB previousStatusType, DateTime updateDate)
        {
            var history = new ObjectiveHistoryDB
            {
                Id = id,
                CurrentStatusType    = currentStatusType,
                CurrentStatusTypeKey = currentStatusType.Key,
                IsNew                 = isNew,
                Objective             = objective,
                ObjectiveId           = objective.Id,
                PreviousStatusType    = previousStatusType,
                PreviousStatusTypeKey = previousStatusType?.Key,
                UpdateDate            = updateDate
            };

            _context.ObjectiveHistories.Add(history);
            _context.SaveChanges();
            return(history);
        }
Ejemplo n.º 3
0
        public async Task <ObjectiveDTO> CreateObjective(ObjectiveDTO dto)
        {
            var mapper = EntityMapping.GetMapper(_mapperConfig);

            var objective = mapper.Map <ObjectiveDB>(dto);

            objective.LastUpdateDate = _dateTimeWrapper.Now;
            _context.Objectives.Add(objective);

            var history = new ObjectiveHistoryDB
            {
                CurrentStatusTypeKey = objective.StatusTypeKey,
                IsNew                 = true,
                ObjectiveId           = objective.Id,
                PreviousStatusTypeKey = null,
                UpdateDate            = _dateTimeWrapper.Now
            };

            _context.ObjectiveHistories.Add(history);

            await _context.SaveChangesAsync();

            return(mapper.Map <ObjectiveDTO>(objective));
        }