Пример #1
0
        public async Task <StoresResponseModel> UpdateStore(StoresInformation storesInformation, StoresInformation originalInformation)
        {
            // update store using context and returning info with linq
            try
            {
                var updateInfo = StoresInformation.MapUpdate(storesInformation, originalInformation);
                StoresResponseModel response = new StoresResponseModel();
                _context.Entry(updateInfo).State = EntityState.Modified;
                await _context.SaveChangesAsync();

                var list = await(from d in _context.Stores
                                 select new StoresInformation()
                {
                    Id      = d.Id,
                    Address = d.Address,
                    Name    = d.Name
                }).ToListAsync();
                response = StoresResponseModel.Map(list);
                return(response);
            }
            catch (Exception e)
            {
                throw e;
            }
        }
Пример #2
0
        public List <StoreModel> GetStores(ISystemResponse error)
        {
            List <StoreModel> stores = new List <StoreModel>();

            try
            {
                string request = WebAPIClient.GetRequest("Stores", "Get", new Dictionary <string, string>(), error);

                if (!string.IsNullOrEmpty(request) && !error.Error)
                {
                    JavaScriptSerializer serializer = new JavaScriptSerializer();
                    StoresResponseModel  response   = serializer.Deserialize <StoresResponseModel>(request);

                    if (response != null && !error.Error && response.stores != null)
                    {
                        stores = response.stores;
                    }
                }
            }
            catch (Exception ex)
            {
                error.Error     = true;
                error.Message   = "No se pudieron obtener las tiendas";
                error.Exception = ex;
            }

            return(stores);
        }
Пример #3
0
        public StoresResponseModel Create(List <Store> stores)
        {
            StoresResponseModel model = new StoresResponseModel();

            model.total_elements = stores.Count();
            model.stores         = stores.Select(s => Create(s)).ToList();

            return(model);
        }
Пример #4
0
        public async Task <IActionResult> Get()
        {
            try
            {
                var result = await _storeProvider.GetAll();

                var response = new StoresResponseModel(result);
                return(Ok(response));
            }
            catch (Exception)
            {
                var result = new FailureModel(false, (int)HttpStatusCode.BadRequest, "Bad Request");
                return(BadRequest(result));
            }
        }
Пример #5
0
        public async Task <StoresResponseModel> GetAllStores()
        {
            // get all stores using ef code first context
            try
            {
                List <StoresInformation> storesInformation = await _context.Stores.ToListAsync();

                StoresResponseModel storesResponseModel = StoresResponseModel.Map(storesInformation);
                return(storesResponseModel);
            }
            catch (Exception e)
            {
                throw e;
            }
        }
Пример #6
0
        public async Task <StoresResponseModel> AddStore(StoresInformation storesInformation)
        {
            //add store using context and returning info with lambdas and context.
            try
            {
                _context.Stores.Add(storesInformation);
                await _context.SaveChangesAsync();

                List <StoresInformation> response = await _context.Stores.Where(x => x.Id == storesInformation.Id).ToListAsync();

                StoresResponseModel storesResponseModel = StoresResponseModel.Map(response);
                return(storesResponseModel);
            }
            catch (Exception e)
            {
                throw e;
            }
        }