public async Task <IActionResult> GetAllStores(CancellationToken ct)
        {
            var storeEntities = await _storeRepository.GetAllEntities(ct);

            if (storeEntities.Count == 0)
            {
                return(NotFound());
            }

            var stores = new List <Store>();

            foreach (var entity in storeEntities)
            {
                var addressEntity = await _addressRepository.GetEntityAsync(entity.AddressId, ct);

                Store mappedStore = Mapper.Map <Store>(entity);

                Address address = Mapper.Map <Address>(addressEntity);

                mappedStore.Address = address;

                StoreMapEntity map = await _storeMapRepository.GetEntityAsync(entity.StoreMapId, ct);

                StoreMap newMap = Mapper.Map <StoreMap>(map);

                mappedStore.StoreMap = newMap;
                stores.Add(mappedStore);
            }

            return(Ok(stores));
        }
        public static StoreTransfer UpdateStoreTransfer(Dictionary <string, string> values)
        {
            string stNumber = values["STNumber"];
            string stId     = values["STID"];

            StoreTransfer ST = GetStoreTransfer(stNumber);

            ST.Id              = string.IsNullOrEmpty(stId) ? 0 : int.Parse(stId);
            ST.STDate          = values.ContainsKey("Date") ? DateTime.Parse(values["Date"]) : DateTime.Now;
            ST.Customer        = values.ContainsKey("Customer") ? CustomerManager.GetCustomerRef(values["Customer"]) : CustomerManager.GetDefaultRef();
            ST.Origin          = values.ContainsKey("Origin") ? CommonDataManager.GetOrigin(values["Origin"]) : CommonDataManager.GetDefaultRef();
            ST.Size            = values.ContainsKey("Size") ? CommonDataManager.GetOrigin(values["Size"]) : CommonDataManager.GetDefaultRef();
            ST.Vessel          = values.ContainsKey("Vessel") ? CommonDataManager.GetOrigin(values["Vessel"]) : CommonDataManager.GetDefaultRef();
            ST.Quantity        = values.ContainsKey("Quantity") ? decimal.Parse(values["Quantity"]) : 0;
            ST.FromStoreId     = values.ContainsKey("FromStore") ? GetStoreRef(values["FromStore"]) : GetDefaultRef();
            ST.ToStoreId       = values.ContainsKey("ToStore") ? GetStoreRef(values["ToStore"]) : GetDefaultRef();
            ST.VehicleNo       = values.ContainsKey("VehicleNo") ? values["VehicleNo"] : "";
            ST.BiltyNo         = values.ContainsKey("BiltyNo") ? values["BiltyNo"] : "";
            ST.BiltyDate       = values.ContainsKey("BiltyDate") ? DateTime.Parse(values["BiltyDate"]) : DateTime.MinValue;
            ST.RRInvoice       = values.ContainsKey("Invoice") ? values["Invoice"] : "";
            ST.CCMNumber       = values.ContainsKey("CCMNo") ? values["CCMNo"] : "";
            ST.Transporter     = values.ContainsKey("Transporter") ? CommonDataManager.GetTrader(values["Transporter"]) : CommonDataManager.GetDefaultRef();
            ST.StoreInDate     = DateTime.MinValue;
            ST.StoreInQuantity = 0;
            ST.Remarks         = values.ContainsKey("Remarks") ? values["Remarks"] : "";

            StoreDataManager.UpdateStoreTransfer(StoreMap.reMapStoreTransferData(ST));
            ResetCache();
            return(ST);
        }
예제 #3
0
        public JsonResult GetStoreMapDetails(int listId)
        {
            var   userid     = User.Identity.GetUserId();
            var   user       = _dataRepository.GetCurrentUser(userid);
            Store usersstore = user.HomeStore;

            StoreMap     sm        = usersstore.StoreMap;
            List <Shelf> smshelves = sm.Shelves.ToList();

            List <Section> smsections = new List <Section>();

            smshelves.ForEach(x => x.Sections.ToList().ForEach(y => smsections.Add(y)));

            var shoppinglist = _dataRepository.GetShoppingList(listId);
            var itemsinlist  = shoppinglist.ItemsAndLists.Where(il => il.ShoppingListId == listId).Select(x => x.Item).ToList();

            IList <ItemViewModel> list = new List <ItemViewModel>();

            foreach (Item i in itemsinlist)
            {
                list.Add(new ItemViewModel
                {
                    Id          = i.Id,
                    Name        = i.Name,
                    Price       = i.Price,
                    InStock     = i.InStock,
                    StockAmount = i.StockAmount,
                    Aisle       = i.Aisle,
                    Section     = i.Section,
                    Allergens   = i.Allergens
                });
            }

            return(Json(new { shelves = smshelves, sections = smsections, items = list, success = true }, JsonRequestBehavior.AllowGet));
        }
        public static StoreTransfer CreateStoreTransfer(Dictionary <string, string> values)
        {
            StoreTransfer ST = NewStoreTransfer();

            ST.STDate          = values.ContainsKey("Date") ? DateTime.Parse(values["Date"]) : DateTime.Now;
            ST.Customer        = values.ContainsKey("Customer") ? CustomerManager.GetCustomerRef(values["Customer"]) : CustomerManager.GetDefaultRef();
            ST.Origin          = values.ContainsKey("Origin") ? CommonDataManager.GetOrigin(values["Origin"]) : CommonDataManager.GetDefaultRef();
            ST.Size            = values.ContainsKey("Size") ? CommonDataManager.GetOrigin(values["Size"]) : CommonDataManager.GetDefaultRef();
            ST.Vessel          = values.ContainsKey("Vessel") ? CommonDataManager.GetOrigin(values["Vessel"]) : CommonDataManager.GetDefaultRef();
            ST.Quantity        = values.ContainsKey("Quantity") ? decimal.Parse(values["Quantity"]) : 0;
            ST.FromStoreId     = values.ContainsKey("FromStore") ? StoreManager.GetStoreRef(values["FromStore"]) : StoreManager.GetDefaultRef();
            ST.ToStoreId       = values.ContainsKey("ToStore") ? StoreManager.GetStoreRef(values["ToStore"]) : StoreManager.GetDefaultRef();
            ST.VehicleNo       = values.ContainsKey("VehicleNo") ? values["VehicleNo"] : "";
            ST.BiltyNo         = values.ContainsKey("BiltyNo") ? values["BiltyNo"] : "";
            ST.BiltyDate       = values.ContainsKey("BiltyDate") ? DateTime.Parse(values["BiltyDate"]) : DateTime.MinValue;
            ST.RRInvoice       = values.ContainsKey("Invoice") ? values["Invoice"] : "";
            ST.CCMNumber       = values.ContainsKey("CCMNo") ? values["CCMNo"] : "";
            ST.Transporter     = values.ContainsKey("Transporter") ? CommonDataManager.GetTrader(values["Transporter"]) : CommonDataManager.GetDefaultRef();
            ST.StoreInDate     = DateTime.MinValue;
            ST.StoreInQuantity = 0;
            ST.Remarks         = values.ContainsKey("Remarks") ? values["Remarks"] : "";

            StoreDataManager.CreateStoreTransfer(StoreMap.reMapStoreTransferData(ST));

            // ztodo: create store movement record


            ResetCache();
            return(ST);
        }
예제 #5
0
        /// <summary>
        /// On appearing override method
        /// </summary>
        protected override void OnAppearing()
        {
            base.OnAppearing();

            //México city position
            var defaultPosition   = new Position(19.432606, -99.133206);
            var defaultKmDistance = 2;

            StoreMap.MoveToRegion(MapSpan.FromCenterAndRadius(defaultPosition,
                                                              Distance.FromKilometers(defaultKmDistance)));
        }
        public static Seiving CreateSeving(Seiving seiving)
        {
            StoreDataManager.CreateSeving(StoreMap.reMapSeivingData(seiving));

            StoreDataManager.CreateSevingQuantity(StoreMap.reMapSeivingQuantityData(seiving.seivingSizeQty));

            // ztodo: create store movement record


            ResetCache();
            return(seiving);
        }
        public static List <StoreTransfer> ReadAllStoreIO()
        {
            DataTable            DTstoreIO   = StoreDataManager.GetAllStoreInOut();
            List <StoreTransfer> allStoreIOs = StoreMap.MapStoreTransferData(DTstoreIO);

            //foreach (StoreInOut storeIO in allStoreIOs)
            //{
            //    StoreInOut CalculatedStore = CalculateStoreQuantity(storeIO);
            //    AllStores.Add(CalculatedStore);
            //}
            HttpContext.Current.Session.Add(SessionManager.StoreIOSession, allStoreIOs);
            return(allStoreIOs);
        }
        public static List <Store> ReadAllStore()
        {
            DataTable    DTstore          = StoreDataManager.GetAllStore();
            DataTable    DTcustStock      = StoreDataManager.GetAllCustomerStock();
            DataTable    DTstockMovement  = StoreDataManager.GetAllStockMovements();
            List <Store> allStores        = StoreMap.MapStoreData(DTstore, DTcustStock, DTstockMovement);
            List <Store> calculatedStores = new List <Store>();

            foreach (Store store in allStores)
            {
                Store CalculatedStore = CalculateStoreQuantity(store);
                calculatedStores.Add(CalculatedStore);
            }
            HttpContext.Current.Session.Add(SessionManager.StoreSession, calculatedStores);
            _allStores = calculatedStores;
            return(calculatedStores);
        }
        public async Task <IActionResult> GetStore(int id, CancellationToken ct)
        {
            StoreEntity storeEntity = await _storeRepository.GetEntityAsync(id, ct);

            AddressEntity addressEntity = await _addressRepository.GetEntityAsync(storeEntity.AddressId, ct);

            Store mappedStore = Mapper.Map <Store>(storeEntity);

            Address address = Mapper.Map <Address>(addressEntity);

            mappedStore.Address = address;

            StoreMapEntity map = await _storeMapRepository.GetEntityAsync(storeEntity.StoreMapId, ct);

            StoreMap newMap = Mapper.Map <StoreMap>(map);

            mappedStore.StoreMap = newMap;

            return(Ok(mappedStore));
        }
예제 #10
0
        public JsonResult CreateStoreMap(int aisles, int shelves, int sections, bool backwall, bool rightwall, bool leftwall, int storeId)
        {
            if (aisles == 0 || sections == 0 || shelves == 0)
            {
                return(Json(new { error = "Aisles, Sections and/or Shelves equals zero. They all must be greater than zero.", success = false }, JsonRequestBehavior.AllowGet));
            }

            StoreMap map = new StoreMap(aisles, shelves, backwall, rightwall, leftwall);

            Store store = _dataRepository.GetStoreById(storeId);

            if (store != null)
            {
                _dataRepository.CreateStoreMapWithShelves(map, sections, store);
                return(Json(new { success = true }, JsonRequestBehavior.AllowGet));
            }
            else
            {
                return(Json(new { error = "The store was not found", success = false }, JsonRequestBehavior.AllowGet));
            }
        }
예제 #11
0
        //--------------------- End Shelves ----------------------------------------



        //---------------------- Maps ----------------------------------------

        public void CreateStoreMapWithShelves(StoreMap storemap, int sections, Store store)
        {
            var count = 1;

            for (int i = 0; i < storemap.Aisles - 1; i++)
            {
                Shelf shelf = new Shelf(count.ToString(), sections);
                AddShelf(shelf);
                storemap.Shelves.Add(shelf);
                count++;
            }


            if (storemap.BackWall)
            {
                Shelf shelf = new Shelf("backwall", sections);
                AddShelf(shelf);
                storemap.Shelves.Add(shelf);
            }
            if (storemap.RightSection)
            {
                Shelf shelf = new Shelf("Right", sections);
                AddShelf(shelf);
                storemap.Shelves.Add(shelf);
            }
            if (storemap.LeftSection)
            {
                Shelf shelf = new Shelf("Left", sections);
                AddShelf(shelf);
                storemap.Shelves.Add(shelf);
            }

            _databaseContext.Maps.Add(storemap);
            _databaseContext.SaveChanges();


            store.StoreMap = storemap;
            //store.StoreMapId = storemap.Id;
            _databaseContext.SaveChanges();
        }
예제 #12
0
        protected async override void OnNavigatedTo(NavigationEventArgs e)
        {
            try
            {
                //base.OnNavigatedTo(e);
                StoreMap.MapServiceToken = "LjAtiC5aNFPpcxSyy29M~HCQIpzUD7UFVDw77JI1Xmg~Ai8yD06vGSyqxPxKwhV2yLuG4eanMbZEphNpVsJwSt-r7cWmt3f46xM-ka1PVNsC";
                var locator = new Geolocator();
                //sets accuracy to 100 (Best accuracy)
                locator.DesiredAccuracyInMeters = 100;
                //current location set in "position" variable
                var position = await locator.GetGeopositionAsync();

                await StoreMap.TrySetViewAsync(position.Coordinate.Point, 18D);

                //if position is not empty get lat, long and assign it to icon.Location and add it to the map
                if (position != null)
                {
                    Geopoint myPos = new Geopoint(new BasicGeoposition()
                    {
                        Latitude  = position.Coordinate.Latitude,
                        Longitude = position.Coordinate.Longitude
                    });

                    MapIcon icon = new MapIcon();
                    icon.Location = myPos;
                    icon.Title    = "Home";
                    StoreMap.MapElements.Add(icon);
                }
                //get all the shops added in ShopManager VM
                storeManager = new ShopManager();
            }
            catch (Exception)
            {
                MessageDialog connMsg = new MessageDialog("Connection has not been established, please check your connection.");
                await connMsg.ShowAsync();
            }
        }
        public async Task <IActionResult> ChangeHomeStore(int id, CancellationToken ct)
        {
            var currentUser  = HttpContext.User;
            var userclaim    = currentUser.Claims.First();
            var userId       = Guid.Parse(userclaim.Value);
            var shoppingUser = await _shoppingUserRepository.GetEntityAsync(userId, ct);

            if (shoppingUser == null)
            {
                return(BadRequest("You are not a shopping user"));
            }

            var store = await _storeRepository.GetEntityAsync(id, ct);

            shoppingUser.HomeStoreId = store.Id;

            var updatedUser = await _shoppingUserRepository.UpdateEntity(shoppingUser, ct);

            if (updatedUser.HomeStoreId != store.Id)
            {
                return(BadRequest("Error updating users store"));
            }

            AddressEntity addressEntity = await _addressRepository.GetEntityAsync(store.AddressId, ct);

            Store   mappedStore = Mapper.Map <Store>(store);
            Address address     = Mapper.Map <Address>(addressEntity);

            mappedStore.Address = address;

            StoreMapEntity map = await _storeMapRepository.GetEntityAsync(store.StoreMapId, ct);

            StoreMap newMap = Mapper.Map <StoreMap>(map);

            mappedStore.StoreMap = newMap;

            var lists = await _shoppingListRepository.GetAllShoppingListsForUserForACertainStore(shoppingUser.Id, mappedStore.Id, ct);

            List <ShoppingList> newlist = new List <ShoppingList>();

            //sle = ShoppingListEntity
            foreach (var sle in lists)
            {
                ShoppingList sl = new ShoppingList
                {
                    Name = sle.Name,
                    //Store = mappedStore,
                    TimeOfCreation = sle.TimeOfCreation,
                    Id             = sle.Id
                };

                var itemListLinkEntities = await _itemListLinkRepository.GetAllByShoppingListId(sle.Id, ct);

                foreach (var itemlistlink in itemListLinkEntities)
                {
                    ShoppingListItem item = await GetFullItemInfo(itemlistlink, sle.StoreId, ct);

                    sl.Items.Add(item);
                }

                sl.TotalCost  = sl.Items.Select(i => i.Price * i.ItemQuantity).ToList().Sum();
                sl.TotalItems = sl.Items.Select(i => i.ItemQuantity).ToList().Sum();

                newlist.Add(sl);
            }

            var updatedUserApp = new ShoppingUser
            {
                FullName      = $"{shoppingUser.FirstName} {shoppingUser.LastName}",
                Email         = shoppingUser.Email,
                HomeStore     = mappedStore,
                ShoppingLists = newlist,
                Role          = "Shopping"
            };

            return(Ok(updatedUserApp));
        }
예제 #14
0
        public async Task <IActionResult> LoginUser([FromBody] LoginUser user, CancellationToken ct)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(new { error = "Model state is not valid" }));
            }

            var result = await _baseSignInManager.PasswordSignInAsync(user.Email, user.Password, false, false);

            if (!result.Succeeded)
            {
                return(BadRequest(new { error = $"Unable to sign in user {user.Email}" }));
            }

            var userEntity = await _baseUserManager.FindByEmailAsync(user.Email);

            var rolenames = await _baseUserManager.GetRolesAsync(userEntity) as List <string>;

            if (rolenames[0] == "Shopping")
            {
                try
                {
                    var         shoppingUserEntity = userEntity as ShoppingUserEntity;
                    StoreEntity storeEntity        = await _storeRepository.GetEntityAsync(shoppingUserEntity.HomeStoreId, ct);

                    AddressEntity addressEntity = await _addressRepository.GetEntityAsync(storeEntity.AddressId, ct);

                    Store   mappedStore = Mapper.Map <Store>(storeEntity);
                    Address address     = Mapper.Map <Address>(addressEntity);
                    mappedStore.Address = address;

                    StoreMapEntity map = await _storeMapRepository.GetEntityAsync(storeEntity.StoreMapId, ct);


                    StoreMap newMap = Mapper.Map <StoreMap>(map);

                    mappedStore.StoreMap = newMap;

                    var lists = await _shoppingListRepository.GetAllShoppingListsForUserForACertainStore(shoppingUserEntity.Id, mappedStore.Id, ct);

                    List <ShoppingList> newlist = new List <ShoppingList>();

                    //sle = ShoppingListEntity
                    foreach (var sle in lists)
                    {
                        ShoppingList sl = new ShoppingList
                        {
                            Name = sle.Name,
                            //Store = mappedStore,
                            TimeOfCreation = sle.TimeOfCreation,
                            Id             = sle.Id
                        };

                        var itemListLinkEntities = await _itemListLinkRepository.GetAllByShoppingListId(sle.Id, ct);

                        foreach (var itemlistlink in itemListLinkEntities)
                        {
                            ShoppingListItem item = await GetFullItemInfo(itemlistlink, sle.StoreId, ct);

                            sl.Items.Add(item);
                        }

                        sl.TotalCost  = sl.Items.Select(i => i.Price * i.ItemQuantity).ToList().Sum();
                        sl.TotalItems = sl.Items.Select(i => i.ItemQuantity).ToList().Sum();

                        newlist.Add(sl);
                    }

                    var shoppingUser = new ShoppingUser
                    {
                        Token         = CreateToken(shoppingUserEntity),
                        FullName      = $"{shoppingUserEntity.FirstName} {shoppingUserEntity.LastName}",
                        Email         = shoppingUserEntity.Email,
                        HomeStore     = mappedStore,
                        ShoppingLists = newlist,
                        Role          = "Shopping"
                    };

                    var response = new ObjectResult(shoppingUser)
                    {
                        StatusCode = (int)HttpStatusCode.OK
                    };

                    Request.HttpContext.Response.Headers.Add("authorization", shoppingUser.Token);


                    return(response);
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex);
                }
            }
            else if (rolenames[0] == "Store")
            {
                var storeUserEntity = userEntity as StoreUserEntity;
                var storeUser       = new StoreUser
                {
                    Token    = CreateToken(storeUserEntity),
                    FullName = $"{storeUserEntity.FirstName}, {storeUserEntity.LastName}",
                    Email    = storeUserEntity.Email,
                    Role     = "Store"
                };

                if (storeUserEntity.HomeStoreId != 0)
                {
                    StoreEntity storeEntity = await _storeRepository.GetEntityAsync(storeUserEntity.HomeStoreId, ct);

                    AddressEntity addressEntity = await _addressRepository.GetEntityAsync(storeEntity.AddressId, ct);

                    Store   mappedStore = Mapper.Map <Store>(storeEntity);
                    Address address     = Mapper.Map <Address>(addressEntity);
                    mappedStore.Address = address;
                    storeUser.Store     = mappedStore;
                }
                else
                {
                    storeUser.Store = null;
                }

                var response = new ObjectResult(storeUser)
                {
                    StatusCode = (int)HttpStatusCode.OK
                };

                Request.HttpContext.Response.Headers.Add("authorization", storeUser.Token);


                return(response);
            }
            else if (rolenames[0] == "Admin")
            {
            }

            return(BadRequest(new { error = $"Could not find user with role {rolenames[0]}" }));
        }
예제 #15
0
        public static bool CreateDutyClear(DutyClear dcl)
        {
            try
            {
                if (dcl.PO != null && dcl.PO.Id != Guid.Empty && dcl.PODetail != null && dcl.PODetail.Id != Guid.Empty)
                {
                    Guid dclId = PurchaseDataManager.CreateDCL(POMap.reMapDCLData(dcl));
                    dcl.Id = dclId;
                    PurchaseOrder po = GetPO(dcl.PO.Name);
                    StoreDataManager.CreateStockMovement(StoreMap.reMapStockMovementData(po, dcl)); //TODO
                    ResetCache();
                }
                return(true);
            }
            catch (Exception ex)
            {
                ExceptionHandler.Error("Something went wrong. Details: " + ex.Message, ex);
            }
            return(false);


            /*string poNumber = keyvalues.ContainsKey("PO") ? keyvalues["PO"] : "";
             * string cusId = keyvalues.ContainsKey("Customer") ? keyvalues["Customer"] : "";
             *
             * if (poNumber != "" && cusId != "")
             * {
             *  PurchaseOrder PO = GetPO(poNumber);
             *  PODetail POD = null;
             *  foreach (PODetail pod in PO.PODetailsList)
             *  {
             *      if (pod.Customer.Id == new Guid(cusId))
             *          POD = pod;
             *  }
             *  if (POD != null)
             *  {
             *      if (POD.DutyClearsList == null)
             *          POD.DutyClearsList = new List<DutyClear>();
             *      DutyClear Dcl = NewDCL();
             *      Dcl.PO = new Reference() { Id = PO.Id, Name = PO.PONumber };
             *      Dcl.PODetail = new Reference() { Id = POD.Id, Name = PO.PONumber };
             *      if (keyvalues.ContainsKey("Store"))
             *          Dcl.Store = StoreManager.GetStoreRef(keyvalues["Store"].ToString());
             *      Dcl.Quantity = keyvalues.ContainsKey("Quantity") ? decimal.Parse(keyvalues["Quantity"]) : 0;
             *      Dcl.Remarks = keyvalues.ContainsKey("Remarks") ? keyvalues["Remarks"] : "";
             *      POD.DutyClearsList.Add(Dcl);
             *
             *      PurchaseDataManager.CalculatePO(PO);
             *      if (PO.isValid)
             *      {
             *          PurchaseDataManager.CreateDCL(POMap.reMapDCLData(Dcl));
             *          //todo stock movement
             *      }
             *      else
             *      {
             *          ExceptionHandler.Error("Something went wrong! PO Quantity is not valid.");
             *          PurchaseDataManager.ResetCache();
             *          return null;
             *      }
             *      PurchaseDataManager.ResetCache();
             *      return Dcl;
             *  }
             * }
             * return null;*/
        }