public ActionResult AddScheme(AddSchemeViewModel model) { ServiceResult result = new ServiceResult(); try { SchemeItem entity = new SchemeItem(); entity.MediaID = model.id; entity.StartTime = Convert.ToDateTime(model.startTime); entity.EndTime = Convert.ToDateTime(model.endTime); entity.Price = Convert.ToDecimal(model.price); entity.PeriodCode = model.periodCode; entity.PeriodCount = model.periodCount; if (string.IsNullOrEmpty(model.Name) && model.schemeId != 0) { entity.SchemeID = model.schemeId; if (SchemeItemService.GetALL().Any(x => x.MediaID == model.id && x.SchemeID == model.schemeId)) { result.AddServiceError("该方案已经包含了此媒体"); result.Message = "该方案已经包含了此媒体!"; } } else { Scheme scheme = new Scheme() { AddTime = DateTime.Now, Name = model.Name, Description = model.Description, LastTime = DateTime.Now, MemberID = CookieHelper.MemberID }; SchemeService.Create(scheme); entity.SchemeID = scheme.ID; } if (result.Success) { SchemeItemService.Create(entity); result.Message = "加入方案成功!"; } } catch (Exception ex) { result.Message = "加入方案失败!"; result.AddServiceError(Utilities.GetInnerMostException(ex)); LogHelper.WriteLog("用户:" + CookieHelper.MemberID + "加入方案失败!", ex); } return(Json(result, JsonRequestBehavior.AllowGet)); }
public async Task <ActionResult> AddScheme(Guid organisationId) { await SetBreadcrumb(null, InternalUserActivity.ManageScheme); using (var client = apiClient()) { AddSchemeViewModel viewModel = new AddSchemeViewModel() { CompetentAuthorities = await GetCompetentAuthorities(), ComplianceYears = await client.SendAsync(User.GetAccessToken(), new GetComplianceYears(organisationId)), OrganisationId = organisationId, OrganisationName = (await cache.FetchOrganisationName(organisationId)), IsChangeableStatus = true, OrganisationAddress = new AddressData() }; viewModel.OrganisationAddress.Countries = await client.SendAsync(User.GetAccessToken(), new GetCountries(false)); return(View(viewModel)); } }
public async Task <ActionResult> AddScheme(AddSchemeViewModel model) { using (var client = apiClient()) { if (!ModelState.IsValid) { model.CompetentAuthorities = await GetCompetentAuthorities(); model.ComplianceYears = await client.SendAsync(User.GetAccessToken(), new GetComplianceYears(model.OrganisationId)); model.OrganisationAddress.Countries = await client.SendAsync(User.GetAccessToken(), new GetCountries(false)); await SetBreadcrumb(null, InternalUserActivity.ManageScheme); return(View(model)); } CreateScheme request = new CreateScheme( model.OrganisationId, model.SchemeName, model.ApprovalNumber, model.IbisCustomerReference, model.ObligationType.Value, model.CompetentAuthorityId, SchemeStatus.Approved); CreateOrUpdateSchemeInformationResult result = await client.SendAsync(User.GetAccessToken(), request); await cache.InvalidateOrganisationSearch(); switch (result.Result) { case CreateOrUpdateSchemeInformationResult.ResultType.Success: SchemeData orgData = new SchemeData() { OrganisationId = model.OrganisationId, Contact = model.Contact, Address = model.OrganisationAddress, }; await client.SendAsync(User.GetAccessToken(), new UpdateSchemeContactDetails(orgData)); return(RedirectToAction("ManageSchemes")); case CreateOrUpdateSchemeInformationResult.ResultType.ApprovalNumberUniquenessFailure: { ModelState.AddModelError("ApprovalNumber", "Approval number already exists"); await SetBreadcrumb(null, InternalUserActivity.ManageScheme); model.CompetentAuthorities = await GetCompetentAuthorities(); model.ComplianceYears = await client.SendAsync(User.GetAccessToken(), new GetComplianceYears(model.OrganisationId)); model.OrganisationAddress.Countries = await client.SendAsync(User.GetAccessToken(), new GetCountries(false)); return(View(model)); } case CreateOrUpdateSchemeInformationResult.ResultType.IbisCustomerReferenceUniquenessFailure: { string errorMessage = string.Format( "Billing reference \"{0}\" already exists for scheme \"{1}\" ({2})", result.IbisCustomerReferenceUniquenessFailure.IbisCustomerReference, result.IbisCustomerReferenceUniquenessFailure.OtherSchemeName, result.IbisCustomerReferenceUniquenessFailure.OtherSchemeApprovalNumber); ModelState.AddModelError("IbisCustomerReference", errorMessage); await SetBreadcrumb(null, InternalUserActivity.ManageScheme); model.CompetentAuthorities = await GetCompetentAuthorities(); model.ComplianceYears = await client.SendAsync(User.GetAccessToken(), new GetComplianceYears(model.OrganisationId)); model.OrganisationAddress.Countries = await client.SendAsync(User.GetAccessToken(), new GetCountries(false)); return(View(model)); } case CreateOrUpdateSchemeInformationResult.ResultType.IbisCustomerReferenceMandatoryForEAFailure: ModelState.AddModelError("IbisCustomerReference", "Enter a customer billing reference"); await SetBreadcrumb(null, InternalUserActivity.ManageScheme); model.CompetentAuthorities = await GetCompetentAuthorities(); model.ComplianceYears = await client.SendAsync(User.GetAccessToken(), new GetComplianceYears(model.OrganisationId)); model.OrganisationAddress.Countries = await client.SendAsync(User.GetAccessToken(), new GetCountries(false)); return(View(model)); default: throw new NotSupportedException(); } } }