public async Task <ActionResult> Put(DTO.InventorySetup model) { if (!this.ModelState.IsValid) { return(this.InvalidModelState(this.ModelState)); } var meta = await AppUsers.GetCurrentAsync(this.Tenant).ConfigureAwait(true); if (!meta.IsAdministrator) { return(this.AccessDenied()); } try { await InventorySetup.SetAsync(this.Tenant, meta.OfficeId, model).ConfigureAwait(false); return(this.Ok()); } catch (Exception ex) { return(this.Failed(ex.Message, HttpStatusCode.InternalServerError)); } }
public static async Task SetAsync(string tenant, int officeId, DTO.InventorySetup model) { var sql = new Sql("UPDATE inventory.inventory_setup"); sql.Append(" SET "); sql.Append("inventory_system = @0,", model.InventorySystem); sql.Append("cogs_calculation_method = @0,", model.CogsCalculationMethod); sql.Append("allow_multiple_opening_inventory = @0,", model.AllowMultipleOpeningInventory); sql.Append("default_discount_account_id = @0,", model.DefaultDiscountAccountId); sql.Append("validate_returns = @0,", model.ValidateReturns); sql.Append("use_pos_checkout_screen = @0", model.UsePosCheckoutScreen); sql.Where("office_id = @0", officeId); await Factory.NonQueryAsync(tenant, sql).ConfigureAwait(false); }