public async Task <object> AddCause(CauseDTO causeDTO, string userID) { try { var data = new Cause { BeneficiaryAddress = causeDTO.BeneficiaryAddress, TargetAmount = causeDTO.TargetAmount, CauseBeneficiaryAccount = causeDTO.CauseBeneficiaryAccount, BeneficiaryNumber = causeDTO.BeneficiaryNumber, DateCountDown = causeDTO.DateCountDown, Description = causeDTO.Description, Donation = causeDTO.Donation, Duration = causeDTO.Duration, ExpectedProjectImpact = causeDTO.ExpectedProjectImpact, PicturePath = causeDTO.PicturePath, Title = causeDTO.Title, VideoPath = causeDTO.VideoPath, UserID = userID, DateCreated = DateTime.Now }; await dataContext.AddAsync(data); int result = await dataContext.SaveChangesAsync(); if (result > 0) { var email = new EmailDTO { Subject = "New Cause Request Submitted", Body = string.Format(_configuration.GetValue <string>("Cause"), _configuration.GetValue <string>("ServerUrl"), "userObj.ConfirmationToken"), SourceEmail = "*****@*****.**", DestinatonEmail = "*****@*****.**" }; await _mailService.SendMail(email); res.Success = true; res.Data = data; return(res); } else { res.Success = false; res.Message = "Db Error"; return(res); } } catch (Exception ex) { throw new Exception(ex.Message); } }
public async Task <object> UpdateCause(CauseDTO causeDTO, Guid Id) { try { var update = await dataContext.Cause.Where(p => p.Id == Id).FirstOrDefaultAsync(); if (update != null) { update.BeneficiaryAddress = causeDTO.BeneficiaryAddress; update.TargetAmount = causeDTO.TargetAmount; update.CauseBeneficiaryAccount = causeDTO.CauseBeneficiaryAccount; update.BeneficiaryNumber = causeDTO.BeneficiaryNumber; update.DateCountDown = causeDTO.DateCountDown; update.Description = causeDTO.Description; update.Donation = causeDTO.Donation; update.Duration = causeDTO.Duration; update.ExpectedProjectImpact = causeDTO.ExpectedProjectImpact; update.PicturePath = causeDTO.PicturePath; update.Title = causeDTO.Title; update.VideoPath = causeDTO.VideoPath; int result = await dataContext.SaveChangesAsync(); if (result > 0) { res.Success = true; res.Message = "Cause successfully updated"; res.Data = update; return(res); } else { res.Success = false; res.Message = "Db Error"; return(res); } } else { res.Success = false; res.Message = "Cause id does not exist"; res.Data = null; return(res); } } catch (Exception ex) { throw new Exception(ex.Message); } }
public async Task <IActionResult> UpdateCause(CauseDTO causeDTO, Guid Id) { try { dynamic result = await _cause.UpdateCause(causeDTO, Id); if (result.Success == false) { return(BadRequest(result)); } return(Ok(result)); } catch (Exception ex) { throw; } }
public async Task <IActionResult> AddCause(CauseDTO causeDTO) { try { //var userid = _accessor.HttpContext.User.Claims.Where(c => c.Type == ClaimTypes.NameIdentifier).SingleOrDefault(); var userid = "B7C60175-B370-4CE4-AC86-08D81D38F5FE"; dynamic result = await _cause.AddCause(causeDTO, userid); if (result.Success == false) { return(BadRequest(result)); } return(Ok(result)); } catch (Exception ex) { throw; } }