Exemplo n.º 1
0
        public async Task <TransactionResult> DeleteProjectFundingLevel(ProjectFundingLevelDTO projectFundingLevelDTO, string user)
        {
            try
            {
                AspNetUsers _user = await context.AspNetUsers.Where(u => u.UserName == user).FirstOrDefaultAsync();

                Project _project = null;
                if (projectFundingLevelDTO.ProjectFK != null)
                {
                    _project = await context.Project.FindAsync(projectFundingLevelDTO.ProjectFK);
                }

                if (_project.AspNetUsers != _user)
                {
                    return(new TransactionResult(TransResult.Fail, "This is not your project", null));
                }

                ProjectFundingLevel projectFundingLevel = await context.ProjectFundingLevel.FindAsync(projectFundingLevelDTO.Id);

                projectFundingLevel.IsActive = false;
                await context.SaveChangesAsync();

                return(new TransactionResult(TransResult.Success, "Success", null));
            }
            catch (Exception ex) { return(new TransactionResult(TransResult.Fail, ex.Message, ex)); }
        }
Exemplo n.º 2
0
        public async Task <TransactionResult> SaveProjectFundingTransaction(ProjectFundingLevelDTO projectFundingLevelDTO, string user)
        {
            try
            {
                AspNetUsers _user = await context.AspNetUsers.Where(u => u.UserName == user).FirstOrDefaultAsync();

                Project _project = null;
                if (projectFundingLevelDTO.ProjectFK != null)
                {
                    _project = await context.Project.FindAsync(projectFundingLevelDTO.ProjectFK);
                }

                if (_project.AspNetUsers != _user)
                {
                    return(new TransactionResult(TransResult.Fail, "This is not your project", null));
                }

                if (projectFundingLevelDTO.Id == null || projectFundingLevelDTO.Id == 0)
                {
                    ProjectFundingLevel projectFundingLevel = new ProjectFundingLevel()
                    {
                        Project = _project,
                        Title   = projectFundingLevelDTO.Title,
                        Amount  = projectFundingLevelDTO.Amount != null?Convert.ToDecimal(projectFundingLevelDTO.Amount) : 0,
                                      Rewards  = projectFundingLevelDTO.Rewards,
                                      IsActive = projectFundingLevelDTO.IsActive != null ? (bool)projectFundingLevelDTO.IsActive : true
                    };
                    context.ProjectFundingLevel.Add(projectFundingLevel);
                    await context.SaveChangesAsync();

                    return(new TransactionResult(TransResult.Success, "Success", null, projectFundingLevel.Id));
                }
                else
                {
                    ProjectFundingLevel projectFundingLevel = await context.ProjectFundingLevel.FindAsync(projectFundingLevelDTO.Id);

                    projectFundingLevel.Project  = _project;
                    projectFundingLevel.Title    = projectFundingLevelDTO.Title;
                    projectFundingLevel.Amount   = projectFundingLevelDTO.Amount != null ? (decimal)projectFundingLevelDTO.Amount : 0;
                    projectFundingLevel.Rewards  = projectFundingLevelDTO.Rewards;
                    projectFundingLevel.IsActive = projectFundingLevelDTO.IsActive != null ? (bool)projectFundingLevelDTO.IsActive : true;
                    await context.SaveChangesAsync();

                    return(new TransactionResult(TransResult.Success, "Success", null));
                }
            }
            catch (Exception ex) { return(new TransactionResult(TransResult.Fail, ex.Message, ex)); }
        }