public async Task <ActionResult> AddEditPrePlanning(string id) { try { PrePlanningModel model = await PrepareEditingDataAsync(id); await FillLookUpsAsync(model, id); return(View(model)); } catch (BusinessRuleException ex) { AddError(ex.Message); PrePlanningModel model = await PrepareEditingDataAsync(id); await FillLookUpsAsync(model, id); return(View(model)); } catch (AuthorizationException ex) { AddError(ex.Message); return(RedirectToAction(nameof(Index))); } catch (UnHandledAccessException ex) { AddError(ex.Message); return(RedirectToAction(nameof(Index))); } catch (Exception e) { AddError(Resources.TenderResources.ErrorMessages.UnexpectedError); return(RedirectToAction(nameof(Index))); } }
public async Task <PrePlanningModel> CreateAsync(PrePlanningModel model) { Check.ArgumentNotNull(nameof(model), model); PrePlanning planning; await _prePlanningDomainService.CheckNameExist(model.ProjectName, model.BranchId, model.YearQuarterId, model.AgencyCode, model.PrePlanningId); if (model.PrePlanningId == 0) { planning = new PrePlanning(model.PrePlanningId, model.AgencyCode, model.BranchId, model.ProjectName, model.ProjectNature, model.ProjectTypeId, model.ProjectDescription, model.InsideKSA, (int)Enums.PrePlanningStatus.UnderUpdate, model.Duration, model.DurationInDays, model.DurationInMonths, model.DurationInYears, model.YearQuarterId); planning.IsDurationValid(); planning.AddtAreasCountriesTypes(model.PrePlanningAreaIDs, model.InsideKSA, model.PrePlanningCountriesIDs, model.ProjectTypesIDs); planning = await _genericCommandRepository.CreateAsync <PrePlanning>(planning); } else { planning = await _prePlanningQueries.FindByIdForEdit(model.PrePlanningId); if (planning.StatusId == (int)Enums.PrePlanningStatus.Pending || planning.StatusId == (int)Enums.PrePlanningStatus.Rejected) { throw new UnHandledAccessException(); } planning.Update(model.AgencyCode, model.ProjectName, model.ProjectNature, model.ProjectDescription, model.InsideKSA, (int)Enums.PrePlanningStatus.UnderUpdate, model.Duration, model.DurationInDays, model.DurationInMonths, model.DurationInYears, model.YearQuarterId); planning.IsDurationValid(); planning = planning.UpdatetAreasCountriesTypes(model.PrePlanningAreaIDs, model.InsideKSA, model.PrePlanningCountriesIDs, model.ProjectTypesIDs); _genericCommandRepository.Update <PrePlanning>(planning); } await _genericCommandRepository.SaveAsync(); model.PrePlanningId = planning.PrePlanningId; return(model); }
public async Task <PrePlanningModel> Add([FromBody] PrePlanningModel model) { model.AgencyCode = User.UserAgency(); model.BranchId = User.UserBranch(); PrePlanningModel PreplanningModel = await _prePlanningAppService.CreateAsync(model); return(PreplanningModel); }
public async Task <PrePlanningModel> SetPrePlanningLookUps() { PrePlanningModel preplanning = await _prePlanningQueries.SetPrePlanningLookUps(); if (preplanning == null) { throw new UnHandledAccessException(); } return(preplanning); }
public async Task <PrePlanningModel> GetPrePlanningDetailsById(int id) { PrePlanningModel preplanning = await _prePlanningQueries.GetPrePlanningDetailsById(id); if (preplanning == null) { throw new UnHandledAccessException(); } return(preplanning); }
public async Task ShouldCreateAsyncThrowException_When_DurationInDaysLessThanZero() { PrePlanningModel model = new PrePlanningModel() { PrePlanningId = 0, BranchId = 1, YearQuarterId = 1, ProjectName = "ProjectName", AgencyCode = "1" }; await Assert.ThrowsAsync <BusinessRuleException>(async() => await _sut.CreateAsync(model)); }
private async Task FillLookUpsAsync(PrePlanningModel model, string id) { PrePlanningLookUpsModels lookUps = await _cache.GetOrCreateAsync(CacheKeys.PrePlanningCache /* + "_" + HttpContext.Session.Id*/, async entry => { int minutes = int.Parse(_rootConfiguration.CachingConfiguration.CachingMinutes /*_configuration.GetSection("Chaching:CachingMinutes").Value*/); entry.SlidingExpiration = TimeSpan.FromMinutes(minutes); return(await _ApiClient.GetAsync <PrePlanningLookUpsModels>("Lookup/GetPrePlanningLookups", null)); }); List <SelectListItem> activitiesItems = new List <SelectListItem>(); foreach (var item in lookUps.ProjectTypes) { var group = new SelectListGroup { Name = item.Name }; foreach (var sub in item.SubActivities) { activitiesItems.Add(new SelectListItem { Value = sub.ActivityId.ToString(), Text = sub.Name, Group = group }); } } List <LookupModel> yearQuarter = new List <LookupModel>(lookUps.YearQuarters);; model.ProjectTypesList = activitiesItems; model.YearQuarters = yearQuarter; model.Areas = lookUps.Areas; model.Countries = lookUps.Countries; model.EncyptedPrePlanningId = id; if (DateTime.Now.Month == 4 || DateTime.Now.Month == 5 || DateTime.Now.Month == 6) { model.YearQuarters.Remove(model.YearQuarters[0]); } else if (DateTime.Now.Month == 7 || DateTime.Now.Month == 8 || DateTime.Now.Month == 9) { model.YearQuarters.Remove(model.YearQuarters[0]); model.YearQuarters.Remove(model.YearQuarters[0]); } else if (DateTime.Now.Month == 10 || DateTime.Now.Month == 11 || DateTime.Now.Month == 12) { model.YearQuarters.Remove(model.YearQuarters[0]); model.YearQuarters.Remove(model.YearQuarters[0]); model.YearQuarters.Remove(model.YearQuarters[0]); } }
public async Task <PrePlanningModel> SetPrePlanningLookUps() { var result = new PrePlanningModel { PrePlanningAreaIDs = new List <int>(), PrePlanningCountriesIDs = new List <int>(), ProjectTypesIDs = new List <int>(), Countries = _context.Countries.Select(r => new CountryModel { CountryId = r.CountryId, Name = r.NameAr }).ToList(), Areas = _context.Areas.Select(r => new LookupModel { Id = r.AreaId, Name = r.NameAr }).ToList(), }; return(result); }
public async Task ShouldCreateAsyncThrowException() { _moqPrePlanningQueries.Setup(x => x.FindByIdForEdit(It.IsAny <int>(), It.IsAny <int>())) .Returns(() => { return(Task.FromResult <Core.Entities.PrePlanning>(prePlanningDefaults.GetPrePlanningDataForReOpen())); }); PrePlanningModel model = new PrePlanningModel() { PrePlanningId = 1, BranchId = 1, YearQuarterId = 1, ProjectName = "ProjectName", AgencyCode = "1", DurationInDays = 1 }; await Assert.ThrowsAsync <UnHandledAccessException>(async() => await _sut.CreateAsync(model)); }
private async Task <PrePlanningModel> PrepareEditingDataAsync(string id, PrePlanningModel model = null) { model = model ?? new PrePlanningModel(); if (!string.IsNullOrEmpty(id)) { model = await _ApiClient.GetAsync <PrePlanningModel>("PrePlanning/GetPrePlanningModelById/" + Util.Decrypt(id), null); if (model.StatusId == (int)Enums.PrePlanningStatus.Pending || model.StatusId == (int)Enums.PrePlanningStatus.Rejected) { throw new BusinessRuleException(Resources.SharedResources.ErrorMessages.NotAddedAuthorized); } } else { model = await _ApiClient.GetAsync <PrePlanningModel>("PrePlanning/SetPrePlanningLookUps", null); } return(model); }
public async Task GetPrePlanningDetailsById_Returns_Data() { var _id = 1; var _prePlanningModel = new PrePlanningModel() { AgencyCode = "018001000000", BranchId = 5, InsideKSA = true, }; var result = await _prePlanningController.GetPrePlanningDetailsById(_id); Assert.NotNull(result); Assert.IsType <PrePlanningModel>(result); Assert.Equal(_prePlanningModel.AgencyCode, result.AgencyCode); Assert.NotEmpty(result.PrePlanningAreaIDs); Assert.NotEmpty(result.ProjectTypesIDs); Assert.True(result.InsideKSA); }
public async Task ShouldCreateAsyncSuccess() { _moqPrePlanningQueries.Setup(x => x.FindByIdForEdit(It.IsAny <int>(), It.IsAny <int>())) .Returns(() => { return(Task.FromResult <Core.Entities.PrePlanning>(prePlanningDefaults.ReturnPrePlanningDefaults())); }); PrePlanningModel model = new PrePlanningModel() { PrePlanningId = 1, BranchId = 1, YearQuarterId = 1, ProjectName = "ProjectName", AgencyCode = "1", DurationInDays = 1 }; await _sut.CreateAsync(model); _moqCommandRepository.Verify(g => g.SaveAsync()); }
public async Task <ActionResult> AddEditPrePlanning(PrePlanningModel model) { if (!ModelState.IsValid) { AddError(Resources.TenderResources.ErrorMessages.ModelDataError); await FillLookUpsAsync(model, model.EncyptedPrePlanningId); return(View(model)); } try { if (!string.IsNullOrEmpty(model.EncyptedPrePlanningId)) { model.PrePlanningId = Util.Decrypt(model.EncyptedPrePlanningId); } PrePlanningModel prePlanningModel = await _ApiClient.PostAsync <PrePlanningModel>("PrePlanning/Add", null, model); AddMessage(Resources.TenderResources.Messages.DataSaved); return(RedirectToAction("Details", new { id = Util.Encrypt(prePlanningModel.PrePlanningId) })); } catch (BusinessRuleException ex) { AddError(ex.Message); } catch (AuthorizationException ex) { throw ex; } catch (Exception ex) { AddError(Resources.TenderResources.ErrorMessages.UnexpectedError); } var myModel = PrepareEditingDataAsync(model.EncyptedPrePlanningId, model); await FillLookUpsAsync(model, model.EncyptedPrePlanningId); return(View(model)); }
public async Task Add_Success() { var _prePlanningModel = new PrePlanningModel() { AgencyCode = "022001000000", BranchId = 1, InsideKSA = true, ProjectName = "Functional Test" + DateTime.Now.Day + DateTime.Now.Hour + DateTime.Now.Millisecond, ProjectNature = "Testing", ProjectDescription = "API Functional Test", Duration = "1", YearQuarterId = 4, DurationInDays = 1, DurationInMonths = 2, DurationInYears = 3 }; _claims = new Claim[3] { new Claim(IdentityConfigs.Claims.BranchId, "1"), new Claim(IdentityConfigs.Claims.isSemiGovAgency, "1"), new Claim(IdentityConfigs.Claims.SelectedCR, "022001000000") }; _prePlanningController = _prePlanningController.WithIdentity(_claims); var result = await _prePlanningController.Add(_prePlanningModel); Assert.NotNull(result); Assert.IsType <PrePlanningModel>(result); Assert.Equal(_prePlanningModel.AgencyCode, result.AgencyCode); Assert.Equal(_prePlanningModel.ProjectName, result.ProjectName); Assert.Equal(_prePlanningModel.ProjectNature, result.ProjectNature); Assert.Equal(_prePlanningModel.ProjectDescription, result.ProjectDescription); Assert.Equal(_prePlanningModel.Duration, result.Duration); Assert.Equal(_prePlanningModel.YearQuarterId, result.YearQuarterId); Assert.True(result.InsideKSA); }