public async Task <IActionResult> CreateTemplate([FromBody] CreateTenantTemplateDataViewModel data) { var retVal = new TenantActionResultViewModel { Message = "OK", Success = true }; try { var tn = db.Tenants.First(n => n.TenantId == data.TenantId); var tm = templateHelper.ExtractTemplate(tn); var template = JsonHelper.ToJson(tm); var tmp = new TenantTemplate { Name = data.Name, Markup = template }; db.TenantTemplates.Add(tmp); await db.SaveChangesAsync(); } catch (Exception ex) { retVal.Success = false; retVal.Message = ex.Message; } return(Json(retVal)); }
protected override LeaseDTO GetNewDraft() { if (_pickedStall == null) { if (!StallPicker.TryPick(AppArgs .MarketState, out _pickedStall)) { return(null); } } var start = _pickedStart ?? DateTime.Now.Date; AllFieldsEnabled = true; WhyInvalid = "Please fill up all required fields."; var draft = new LeaseDTO { ContractStart = start, ContractEnd = start.AddYears(1).Date, Stall = _pickedStall, Rent = _pickedStall.DefaultRent.ShallowClone(), Rights = _pickedStall.DefaultRights.ShallowClone(), RenewedFromID = _renewedFromID, ProductToSell = _productToSell, }; draft.Tenant = TenantTemplate?.ShallowClone() ?? new TenantModel { Country = "Philippines" }; return(draft); }
public async Task <IActionResult> Create([DataSourceRequest] DataSourceRequest request) { var model = new TenantTemplate(); if (ModelState.IsValid) { await this.TryUpdateModelAsync <TenantTemplateViewModel, TenantTemplate>(model); db.TenantTemplates.Add(model); await db.SaveChangesAsync(); } return(Json(await new[] { model.ToViewModel <TenantTemplate, TenantTemplateViewModel>() }.ToDataSourceResultAsync(request, ModelState))); }