public async Task <InitiativeByYear> Edit(Guid initiativeId, InitiativeByYearDto initiativeByYearDto)
        {
            try
            {
                var initiative = await baseContext.InitiativesByYears.Where(x => x.Id == initiativeId).FirstOrDefaultAsync();

                if (initiative == null)
                {
                    return(null);
                }

                if (!String.IsNullOrEmpty(initiativeByYearDto.Year))
                {
                    initiative.InitiativeYearId = initiativeByYearDto.Year;
                }
                if (!(initiativeByYearDto.LeadId == Guid.Empty))
                {
                    initiative.LeadId = initiativeByYearDto.LeadId;
                }

                initiative.UpdatedBy   = "Super User";
                initiative.UpdatedDate = DateTime.UtcNow;

                await SaveChanges();

                return(initiative);
            }
            catch (Exception ex)
            {
                logger.LogError(ex, ex.Message);
                throw ex;
            }
        }
        public async Task <IActionResult> Post(InitiativeByYearDto initiativeByYearDto)
        {
            if (initiativeByYearDto == null)
            {
                logger.LogError("Input object cannot be null");
                return(new BadRequestObjectResult(new { error = "Input object cannot be null" }));
            }

            if (String.IsNullOrEmpty(initiativeByYearDto.Year) || initiativeByYearDto.InitiativeId == Guid.Empty)
            {
                logger.LogError("Some fields are null");
                return(new BadRequestObjectResult(new { error = "Some fields are null" }));
            }

            try
            {
                var result = await inititiativesByYearService.Add(initiativeByYearDto);

                return(Ok(result));
            }
            catch (Exception ex)
            {
                logger.LogError(ex, ex.Message);
                return(BadRequest($"Module not saved, {ex.Message}"));
            }
        }
        public async Task <InitiativeByYear> Add(InitiativeByYearDto initiativeByYearDto)
        {
            try
            {
                var initiative = await baseContext.Initiatives.Where(x => x.Id == initiativeByYearDto.InitiativeId).FirstOrDefaultAsync();

                if (initiative == null)
                {
                    return(null);
                }

                var initiativeByYear = new InitiativeByYear {
                    Id               = Guid.NewGuid(),
                    Name             = $"{initiative.Name} - {initiativeByYearDto.Year}",
                    InitiativeYearId = initiativeByYearDto.Year,
                    InitiativeId     = initiativeByYearDto.InitiativeId,
                    LeadId           = initiativeByYearDto.LeadId,
                    CreatedBy        = "Super Admin",
                    CreatedDate      = DateTime.UtcNow
                };

                baseContext.Add(initiativeByYear);
                await SaveChanges();

                return(initiativeByYear);
            }catch (Exception ex)
            {
                logger.LogError(ex, ex.Message);
                throw ex;
            }
        }
        public async Task <IActionResult> Put([FromRoute] string initiativeId, [FromBody] InitiativeByYearDto initiativeByYearDto)
        {
            if (String.IsNullOrEmpty(initiativeId))
            {
                logger.LogError("Some fields are null");
                return(new BadRequestObjectResult(new { error = "Some fields are null" }));
            }

            if (initiativeByYearDto == null)
            {
                logger.LogError("Input object cannot be null");
                return(new BadRequestObjectResult(new { error = "Input object cannot be null" }));
            }

            try
            {
                var result = await inititiativesByYearService.Edit(new Guid(initiativeId), initiativeByYearDto);

                return(Ok(result));
            }
            catch (Exception ex)
            {
                logger.LogError(ex, ex.Message);
                return(BadRequest($"Module not saved, {ex.Message}"));
            }
        }