//check the intervention and client are in same district or not private bool isInterventionClientInSameDistrict() { var repo = new InterventionsRepository(context); var result = repo.GetInterventionForClientInSameDistrict(intUpdate.InterventionId, Utils.getInstance.GetCurrentUserId()); if (!Utils.getInstance.isNullOrEmpty(result)) { return(true); } else { throw new EditStatusPermissionException(); } }
//used for approving an intervention by manager public IList <InterventionsRepository> ApproveIntervention(int InterventionId, int OldStatus, int NewStatus, string Userid) { try { InterventionsRepository repo = new InterventionsRepository(context); List <InterventionsRepository> interlist = new List <InterventionsRepository>(); repo.Update_Intervention_Status(InterventionId, OldStatus, NewStatus, Userid); return(interlist); } catch { throw new FailedToUpdateRecordException(); } }
//used for cancelling an intervention by manager public IList <InterventionsRepository> CancelIntervention(int interventionId) { try { InterventionsRepository repo = new InterventionsRepository(context); List <InterventionsRepository> interlist = new List <InterventionsRepository>(); repo.Delete(interventionId); return(interlist); } catch { throw new FailedToUpdateRecordException(); } }
//Change the status of a intervention public void ChangeStatus(string intId, string oldStatusText, string newStatusNumber) { intervention.InterventionId = Convert.ToInt32(intId); var intRepo = new InterventionsRepository(context); intervention = intRepo.GetInterventionWithInterventionId(intervention.InterventionId); var oldStatus = (int)Enum.Parse(typeof(Status), oldStatusText); var newStatus = Convert.ToInt32(newStatusNumber); validateUserRole(); validateUserDistrict(); validateHoursCost(); validateOldStatus(oldStatus); var repo = new InterventionsRepository(context); var row = repo.UpdateInterventionStatus(intervention.InterventionId, oldStatus, newStatus); }
//create an intervention public void CreateIntervention(int interventionTypeId, int clientId, string interventionHour, string interventionCost) { var repos = new InterventionsRepository(context); Interventions intervention = new Interventions(); intervention.UserId = HttpContext.Current.User.Identity.GetUserId(); intervention.InterventionTypeId = interventionTypeId; intervention.ClientId = clientId; intervention.CreateDate = DateTime.Now; intervention.InterventionHours = Convert.ToDecimal(interventionHour); intervention.InterventionCost = Convert.ToDecimal(interventionCost); intervention.Status = (validateUserForStatus(intervention.InterventionHours, intervention.InterventionCost)) ? (int)Status.Approved : (int)Status.Proposed; intervention.Operator = ""; try { repos.Insert(intervention); } catch (Exception) { throw new FailedToCreateRecordException(); } }