예제 #1
0
        //[Bind(new string[] { "Name", "Id", "UrlCode" })] Client client
        public async Task <IActionResult> OnPostAsync()
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }

            Client clientToUpdate = new Client
            {
                Id         = Client.Id,
                Name       = Client.Name,
                UrlCode    = Client.UrlCode,
                Active     = Client.Active,
                Properties = Client.Properties
            };

            _db.Attach(clientToUpdate).State = Microsoft.EntityFrameworkCore.EntityState.Modified;

            try
            {
                await _db.SaveChangesAsync();
            }
            catch (Exception)
            {
                return(Page());
            }

            return(RedirectToPage("./Index"));
        }
예제 #2
0
        public async Task <IActionResult> OnPostAsync(ClientCreateModel client)
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }

            Client addClient = new Client {
                Name       = client.Name,
                UrlCode    = client.UrlCode,
                Properties = client.Properties
            };

            _db.Clients.Add(addClient);
            await _db.SaveChangesAsync();

            return(RedirectToPage("./Index"));
        }
예제 #3
0
        public async Task <IActionResult> Create(Store_AddEditModel model)
        {
            if (!ModelState.IsValid)
            {
                model.ClientRetailers = await _db.ClientRetailers
                                        .Where(q => q.ClientId == _client_id)
                                        .Select(s => s.Retailer)
                                        .ToListAsync();

                return(View("New", model));
            }
            ClientStore clientStore = new ClientStore {
                ClientId = _client_id,
                Store    = new Store {
                    Name      = model.Name,
                    Active    = true,
                    Addr_Ln_1 = model.Addr_Ln_1,
                    Addr_Ln_2 = model.Addr_Ln_2,
                    City      = model.City,
                    State     = model.State,
                    Zip       = model.Zip,
                    Country   = "USA",
                    Phone     = model.Phone
                },
                Active = true
            };

            if (!String.IsNullOrEmpty(model.NewRetailer.Name))
            {
                Retailer newRetailer = new Retailer {
                    Name            = model.NewRetailer.Name,
                    ClientRetailers = new List <ClientRetailer> {
                        new ClientRetailer {
                            ClientId = _client_id
                        }
                    }
                };

                _db.Retailers.Add(newRetailer);
                clientStore.Store.Retailer = newRetailer;
            }
            else
            {
                clientStore.Store.RetailerId = model.RetailerId ?? (new Guid());
            }
            Dictionary <string, object> props = new Dictionary <string, object>();

            if (model.MaxOrderAmount != null)
            {
                props.Add("MaxOrderAmount", model.MaxOrderAmount);
            }

            if (model.LocationNumber != null)
            {
                props.Add("LocationNumber", model.LocationNumber);
            }

            if (props.Any())
            {
                clientStore.Properties = new JsonObject <Dictionary <string, object> >
                {
                    Object = props
                }
            }
            ;

            GoogleGeocoding_Location location = GeneralPurpose.GetLatLong(clientStore.Store.Address);

            clientStore.Store.Latitude  = location.lat;
            clientStore.Store.Longitude = location.lng;

            _db.ClientStores.Add(clientStore);
            await _db.SaveChangesAsync();

            IndexStoreWithES(clientStore.Store.Id);

            return(RedirectToAction("Index"));
        }