public IActionResult UpdateRequestStatus(int id) { try { var dbUserOpportunity = _repository.User_Opportunity.GetUserOpportunityById(id); if (dbUserOpportunity.Opportunity_Id == 0 && dbUserOpportunity.User_Id == 0) { _logger.LogError($"opportunity with id: {id}, hasn't been found in db."); return(NotFound()); } var userOpportunity = new User_Opportunity { user_opportunity_id = dbUserOpportunity.user_opportunity_id, Opportunity_Id = dbUserOpportunity.Opportunity_Id, User_Id = dbUserOpportunity.User_Id, Is_Accepted = "true", Request_Date = dbUserOpportunity.Request_Date }; var dbOpportunity = _repository.Opportunity.GetOpportunityById(dbUserOpportunity.Opportunity_Id); var opportunity = dbOpportunity; opportunity.Color = "green"; _repository.Opportunity.UpdateOpportunity(dbOpportunity, opportunity); _repository.User_Opportunity.UpdateUserOpportunity(dbUserOpportunity, userOpportunity); _logger.LogError("data updated"); return(RedirectToAction("opportunities", "admin")); } catch (Exception ex) { _logger.LogError($"Something went wrong inside UpdateOpportunity action: {ex.Message}"); return(StatusCode(500, "Request already approved for this opportunity.")); } }
/// <summary>Maps the specified group.</summary> /// <param name="dbUserOpportunity">The database group.</param> /// <param name="userOpportunity">The group.</param> public static void MapUserOpportunity(this User_Opportunity dbUserOpportunity, User_Opportunity userOpportunity) { dbUserOpportunity.user_opportunity_id = userOpportunity.user_opportunity_id; dbUserOpportunity.Opportunity_Id = userOpportunity.Opportunity_Id; dbUserOpportunity.User_Id = userOpportunity.User_Id; dbUserOpportunity.Is_Accepted = userOpportunity.Is_Accepted; dbUserOpportunity.Request_Date = userOpportunity.Request_Date; }
public IActionResult Apply(int id) { try { var opportunity = _repository.Opportunity.GetOpportunityById(id); var user = _repository.User.GetUserByName(_loggedInUser); var user_opportunity = new User_Opportunity { User_Id = user.user_id, Opportunity_Id = opportunity.o_id, Is_Accepted = "false", Request_Date = DateTime.Today }; if ((opportunity.OpportunityDescription == null && opportunity.o_id == 0) || (user.user_id == 0 && user.UserName == null)) //if the opportunity is not found in db. { _logger.LogError($"opportunity with id: {id}, hasn't been found in db."); return(NotFound()); } var oppr = _repository.Opportunity.GetAllOpportunities().Where(opp => opp.IsVacant.Equals("true")); var oppr1 = _repository.User_Opportunity.GetAllOpportunitiesByUserId(user.user_id); var oppList = new List <Opp_Display>(); foreach (var ptr in oppr) { Opp_Display oppr_update = new Opp_Display(); oppr_update.o_id = ptr.o_id; oppr_update.Opportunity_Description = ptr.OpportunityDescription; oppr_update.Start_Date = ptr.StartTime; oppr_update.End_Date = ptr.EndTime; foreach (var ptr1 in oppr1) { if ((ptr1.Opportunity_Id == ptr.o_id) && (ptr1.Is_Accepted == "false")) { oppr_update.Is_Accepted = "Pending"; //oppList.Add(oppr_update); break; } else if ((ptr1.Opportunity_Id == ptr.o_id) && (ptr1.Is_Accepted == "true")) { oppr_update.Is_Accepted = "Approved"; //oppList.Add(oppr_update); break; } oppr_update.Is_Accepted = "Vacant"; } oppList.Add(oppr_update); } ViewBag.opportunities = oppList; _logger.LogInfo($"Returned all vacant opportunities from database."); _repository.User_Opportunity.CreateUserOpportunity(user_opportunity); return(View("Index")); //return RedirectToAction("Login(login_details)", "User"); } catch (Exception ex) { _logger.LogError($"Something went wrong inside DeleteOpportunity action: {ex.Message}"); return(StatusCode(500, "Already applied for the opportunity")); } }