Пример #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));
        }
Пример #2
0
        public async Task UpdateObjective_Test()
        {
            var dto = new ObjectiveDTO
            {
                Id             = 4,
                Details        = "change details",
                LastUpdateDate = new DateTime(2001, 01, 01),
                Priority       = 7,
                StatusDate     = new DateTime(2001, 01, 01),
                StatusDetails  = "change status details",
                StatusType     = StatusTypes.Postponed,
                Title          = "change title"
            };

            dto = await _provider.UpdateObjective(dto);

            Assert.IsTrue(dto.Id > 0);
            Assert.AreEqual(DEFAULT_DATE_NOW, dto.LastUpdateDate);
            Assert.AreEqual(5, _context.Objectives.Count());
            var allHistories = _context.ObjectiveHistories.ToList();

            Assert.AreEqual(9, allHistories.Count());
            var histories = _context.ObjectiveHistories.Where(x => x.ObjectiveId == dto.Id).ToList();

            Assert.AreEqual(3, histories.Count());
            var history = histories.Single(x => x.CurrentStatusTypeKey == (int)StatusTypes.Postponed);

            Assert.AreEqual((int)StatusTypes.Cancelled, history.PreviousStatusTypeKey);
            Assert.AreEqual((int)StatusTypes.Postponed, history.CurrentStatusType.Key);
            Assert.AreEqual(false, history.IsNew);
        }
Пример #3
0
        public async Task CreateObjective_Test()
        {
            var dto = new ObjectiveDTO
            {
                Id             = 11,
                Details        = "Det",
                LastUpdateDate = new DateTime(2005, 01, 01),
                Priority       = 5,
                StatusDate     = null,
                StatusDetails  = "StaDet",
                StatusType     = StatusTypes.Todo,
                Title          = "Title"
            };

            dto = await _provider.CreateObjective(dto);

            Assert.IsTrue(dto.Id > 0);
            Assert.AreEqual(DEFAULT_DATE_NOW, dto.LastUpdateDate);
            Assert.AreEqual(6, _context.Objectives.Count());
            var allHistories = _context.ObjectiveHistories.ToList();

            Assert.AreEqual(9, allHistories.Count());
            var histories = _context.ObjectiveHistories.Where(x => x.ObjectiveId == dto.Id).ToList();

            Assert.AreEqual(1, histories.Count());
            var history = histories[0];

            Assert.AreEqual(null, history.PreviousStatusType);
            Assert.AreEqual((int)StatusTypes.Todo, history.CurrentStatusType.Key);
            Assert.AreEqual(true, history.IsNew);
        }
Пример #4
0
        public async Task <ObjectiveViewModel> GetAsync(int id)
        {
            ObjectiveDTO objectiveDto = await objectiveService.GetObjectiveAsync(id);

            var objective = mapper.Map <ObjectiveDTO, ObjectiveViewModel>(objectiveDto);

            return(objective);
        }
Пример #5
0
 public async Task <ObjectiveDTO> UpdateObjective(ObjectiveDTO objective)
 {
     try
     {
         return(await _provider.UpdateObjective(objective));
     }
     catch (Exception ex)
     {
         throw new Exception($"Error on updating objective: {ex.Message}");
     }
 }
Пример #6
0
        public async Task <bool> AddObjectiveAsync(ObjectiveDTO objectiveDto)
        {
            Objective objective = mapperDTO.Map <ObjectiveDTO, Objective>(objectiveDto);

            // !!! Тут я не впевниний чи це правильно
            objective.Id = 0;
            //
            objective.Created = DateTime.Now;
            await Database.Objective.CreateAsync(objective);

            await Database.SaveAsync();

            return(true);
        }
Пример #7
0
        public async Task <bool> UpdateObjectiveAsync(ObjectiveDTO objectiveDto)
        {
            if (objectiveDto == null)
            {
                throw new ValidationException("Empty data", "");
            }
            Objective objective = mapperDTO.Map <ObjectiveDTO, Objective>(objectiveDto);

            if (await Database.Objective.UpdateAsync(objective))
            {
                await Database.SaveAsync();

                return(true);
            }
            else
            {
                throw new ValidationException("Cant update objective", "");
            }
        }
        public async Task <ActionResult <Objective> > Post(ObjectiveDTO objectiveData)
        {
            if (objectiveData == null)
            {
                return(BadRequest());
            }

            var newObjective = new Objective()
            {
                Name            = objectiveData.Name,
                Description     = objectiveData.Description,
                StatusObjective = StatusTask.InProcess,
                CreatedTime     = DateTime.Now,
                ExecutorId      = objectiveData.ExecutorId,
                DirectorId      = objectiveData.DirectorId
            };


            db.Objectives.Add(newObjective);
            await db.SaveChangesAsync();

            return(Ok(objectiveData));
        }
Пример #9
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));
        }
Пример #10
0
 public Task Edit(ObjectiveDTO objectiveDto)
 {
     throw new NotImplementedException();
 }
Пример #11
0
 public Task Attach(ObjectiveDTO objectveDto)
 {
     throw new NotImplementedException();
 }
Пример #12
0
 public async Task <ObjectiveDTO> UpdateObjective([FromBody] ObjectiveDTO objective)
 {
     return(await _writerService.UpdateObjective(objective));
 }