Пример #1
0
        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));
        }
Пример #2
0
        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);
        }
Пример #3
0
        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)));
        }