public async Task <AreaTopicResponseModel> CreateAreaTopicAsync(CreateAreaTopicServiceModel model)
        {
            var planArea = await _planAreaObjectService.GetByIdAsync <PlanArea>(model.PlanAreaId);

            AreaTopic areaTopic = new AreaTopic
            {
                PlanAreaId  = model.PlanAreaId,
                PlanId      = planArea.PlanId,
                UserId      = planArea.UserId,
                Name        = model.Name,
                Source      = model.Source,
                Description = model.Description
            };

            if (!model.IsTemplate && !string.IsNullOrEmpty(model.StartDate) && !string.IsNullOrEmpty(model.EndDate))
            {
                areaTopic.StartDate = DateTime.ParseExact(model.StartDate, "yyyy-MM-dd",
                                                          CultureInfo.CurrentCulture);
                areaTopic.EndDate = DateTime.ParseExact(model.EndDate, "yyyy-MM-dd", CultureInfo.CurrentCulture);
            }
            await _topicObjectService.CreateAsync(areaTopic);

            return(new AreaTopicResponseModel
            {
                Id = areaTopic.Id,
                Name = areaTopic.Name,
                PlanId = areaTopic.PlanId
            });
        }
Example #2
0
        public async Task<AreaTopicResponseModel> CreateAreaTopicAsync(CreateAreaTopicServiceModel model)
        {
            var planArea = await _planAreaReadRepository.GetByIdAsync(model.PlanAreaId);
            
            AreaTopic areaTopic = new AreaTopic
            {
                PlanAreaId = model.PlanAreaId,
                PlanId =  planArea.PlanId,
                Name = model.Name,
                StartDate = DateTime.ParseExact(model.StartDate, "yyyy-MM-dd",
                    CultureInfo.CurrentCulture),
                EndDate = DateTime.ParseExact(model.EndDate, "yyyy-MM-dd", CultureInfo.CurrentCulture),
                Source = model.Source,
                Description = model.Description
            };
            await _areaTopicRepository.CreateAsync(areaTopic);
            await _areaTopicRepository.SaveChangesAsync();

            return new AreaTopicResponseModel
            {
                Id = areaTopic.Id,
                Name = areaTopic.Name,
                PlanId = areaTopic.PlanId
            };
        }
Example #3
0
        public async Task <IActionResult> AddTopic(CreateAreaTopicServiceModel model)
        {
            var planArea = await _planAreaService.GetByIdAsync(model.PlanAreaId);

            ValidateUser(planArea.UserId);

            AreaTopicResponseModel response = await _planAreaService.CreateAreaTopicAsync(model);

            return(Json(response));
        }