public bool DeletePledge([FromBody] PledgeOptions pledgeOptions) { if (pledgeOptions != null) { return(_pledgesservices.DeletePledge(pledgeOptions.PledgeId)); } return(false); }
public IActionResult UpdatePledge([FromBody] PledgeOptions pledgeOptions) { var result = _pledgesservices.UpdatePledge(pledgeOptions); if (!result.Success) { return(StatusCode((int)result.ErrorCode, result.ErrorText)); } return(Json(result.Data)); }
public Result <Pledge> UpdatePledge(PledgeOptions pledgeOptions) { if (pledgeOptions == null) { return(Result <Pledge> .CreateFailed( StatusCode.BadRequest, "Null options")); } if (string.IsNullOrWhiteSpace(pledgeOptions.PledgeDescription)) { return(Result <Pledge> .CreateFailed( StatusCode.BadRequest, "Null or empty PledgeDescription")); } if (pledgeOptions.PledgePrice == 0) { return(Result <Pledge> .CreateFailed( StatusCode.BadRequest, "Null or empty PledgePrice")); } if (string.IsNullOrWhiteSpace(pledgeOptions.PledgeReward)) { return(Result <Pledge> .CreateFailed( StatusCode.BadRequest, "Null or empty PledgeReward")); } var pledge = _db.Set <Pledge>().Find(pledgeOptions.PledgeId); pledge.PledgeDescription = pledgeOptions.PledgeDescription; pledge.PledgePrice = pledgeOptions.PledgePrice; pledge.PledgeReward = pledgeOptions.PledgeReward; var rows = 0; try { rows = _db.SaveChanges(); } catch (Exception ex) { return(Result <Pledge> .CreateFailed( StatusCode.InternalServerError, ex.ToString())); } if (rows <= 0) { return(Result <Pledge> .CreateFailed( StatusCode.InternalServerError, "Pledge could not be updated")); } return(Result <Pledge> .CreateSuccessful(pledge)); }
public IQueryable <Pledge> ListPledges(PledgeOptions options) { if (options == null) { return(null); } var query = _db .Set <Pledge>() .AsQueryable(); query = query.Take(500); return(query); }
public Result <Pledge> CreatePledges(PledgeOptions pledgeOptions) { if (pledgeOptions == null) { return(Result <Pledge> .CreateFailed( StatusCode.BadRequest, "Null options")); } var project = projectservices.FindProjectById(pledgeOptions.ProjectId); var pledge = new Pledge { Project = project, PledgeDescription = pledgeOptions.PledgeDescription, PledgePrice = pledgeOptions.PledgePrice, PledgeReward = pledgeOptions.PledgeReward, }; _db.Add(pledge); var rows = 0; try { rows = _db.SaveChanges(); } catch (Exception ex) { return(Result <Pledge> .CreateFailed( StatusCode.InternalServerError, ex.ToString())); } if (rows <= 0) { return(Result <Pledge> .CreateFailed( StatusCode.InternalServerError, "Pledge could not be updated")); } return(Result <Pledge> .CreateSuccessful(pledge)); }
public Result <bool> AddPledgeOptionToProject(string email, int projectId, string titleOfPledge, double priceOfPledge, DateTime estimateDelivery, DateTime durationOfPldege, int numberOfAvailablePledges, string description) { //cheking if the email is valid if (!IsvalidEmail(email)) { resultbool.ErrorCode = 1; resultbool.ErrorText = "not valid email"; resultbool.Data = false; return(resultbool); } //chek if the projcet exist if (!IfProjectExist(projectId)) { resultbool.ErrorCode = 8; resultbool.ErrorText = "projet doesn’t exist"; resultbool.Data = false; return(resultbool); } //cheking if the specific user can modify this projet if (!IsValidateUser(email, projectId)) { resultbool.ErrorCode = 3; resultbool.ErrorText = "This user can't modify this project"; resultbool.Data = false; return(resultbool); } //cheking if the project has already this pledge option var projectPledgeOptions = context.Set <PledgeOptions>().Where(po => po.ProjectId == projectId).ToList(); if (projectPledgeOptions.Any(pc => pc.TitleOfPledge == titleOfPledge)) { resultbool.ErrorCode = 2; resultbool.ErrorText = "this pledge option is already in this project"; resultbool.Data = false; return(resultbool); } //create new pledge option var newPledgeOption = new PledgeOptions(); newPledgeOption.TitleOfPledge = titleOfPledge; newPledgeOption.PriceOfPlege = priceOfPledge; newPledgeOption.NumberOfAvailablePledges = numberOfAvailablePledges; newPledgeOption.ProjectId = projectId; newPledgeOption.NumberOfBacker = 0; newPledgeOption.EstimateDelivery = estimateDelivery; newPledgeOption.DurationOfPledge = durationOfPldege; newPledgeOption.Description = description; context.Add(newPledgeOption); if (context.SaveChanges() >= 1) { resultbool.ErrorCode = 0; resultbool.ErrorText = "Successfull"; resultbool.Data = true; return(resultbool); } else { resultbool.ErrorCode = 4; resultbool.ErrorText = "couldnt save in db"; resultbool.Data = false; return(resultbool); } }