Ejemplo n.º 1
0
        protected override void OnCreate(Bundle bundle)
        {
            base.OnCreate(bundle);
            SetContentView(Resource.Layout.AcListItems);
            string id = Intent.GetStringExtra(Constants.KEY_ID_LIST);

            if (string.IsNullOrEmpty(id))
            {
                return;
            }
            else
            {
                m_data = ListsManager.Instance.GetListByInternalId(id);
                if (m_data == null)
                {
                    return;
                }
            }//else

            llLst             = FindViewById <LinearLayout>(Resource.Id.lstItems);
            txtShoppingItem   = FindViewById <EditText>(Resource.Id.txtItemName);
            txtQuantity       = FindViewById <EditText>(Resource.Id.txtQuantity);
            btnAddItem        = FindViewById <Button>(Resource.Id.btnAddItem);
            btnAddItem.Click += AddNewItem;

            GenerateUIListItems();

            IntentFilter    filter   = new IntentFilter(Intent.ActionSend);
            MessageReciever receiver = new MessageReciever(this);

            LocalBroadcastManager.GetInstance(this).RegisterReceiver(receiver, filter);
        }//OnCreate
Ejemplo n.º 2
0
 /// <summary>
 /// CtrlShoppingList
 /// </summary>
 /// <param name="cnt"></param>
 public CtrlShoppingList(Activity parent, ShApplication cnt, ShoppingListDTO data) : base(cnt)
 {
     this.Id          = View.GenerateViewId();
     m_Data           = data;
     m_ParentActivity = parent;
     Inflate(cnt, Resource.Layout.CtrlShoppingList, this);
     Initialize();
 }//CtrlShoppingList
Ejemplo n.º 3
0
        }//AddNewList

        /// <summary>
        /// CreateUIList
        /// </summary>
        /// <param name="newList"></param>
        /// <param name="progressDialog"></param>
        private void CreateUIList(ShoppingListDTO newList, int position = 0)
        {
            CtrlShoppingList item = new CtrlShoppingList(this, ShAppContext, newList);

            item.Event_DeleteItem += DeleteList;
            item.Event_EditItem   += EditList;
            item.Event_ClickItem  += ClickList;
            llShoppingLst.AddView(item, position);
            llShoppingLst.RequestLayout();
        }//CreateUIList
Ejemplo n.º 4
0
        public async Task <ActionResult> GetSpecificShoppingList(long listId)
        {
            ShoppingListDTO fetchedList = await shoppingListRepository.GetShoppingListByIdAsync(listId);

            if (fetchedList == null)
            {
                return(NotFound());
            }

            return(Ok(dtoMapper.Map <ShoppingList>(fetchedList)));
        }
Ejemplo n.º 5
0
        }//AddNewList

        public void ProcessMessage(Intent intent)
        {
            //intent.GetStringExtra("WearMessage");
            ShoppingListDTO wantedList = ListsManager.Instance.Lists.Where(x => x.InternalId == m_data.InternalId).FirstOrDefault(); //check if the list was not deleted

            if (wantedList == null)
            {
                StartActivity(new Intent(this, typeof(AcShoppingLists)));
                return;
            }//endif

            var allUiLists = wantedList.Items.Where(x => x.IsDeleted == false).OrderBy(x => x.Date).ToList();

            ViewGroup viewGroup = (ViewGroup)llLst;

            //remove all that are not in the datalist
            for (int i = 0; i < viewGroup.ChildCount; i++)
            {
                CtrlItemList child = viewGroup.GetChildAt(i) as CtrlItemList;
                if (child == null)
                {
                    continue;
                }
                var foundItem = allUiLists.Where(x => x.InternalId == child.Data.InternalId).FirstOrDefault();
                if (foundItem == null)
                {
                    ((child as View).Parent as ViewGroup).RemoveView(child);
                }
            }//for

            for (int i = 0; i < allUiLists.Count; i++)
            {
                CtrlItemList wantedView = null;
                for (int j = 0; j < viewGroup.ChildCount; j++)
                {
                    CtrlItemList child = viewGroup.GetChildAt(j) as CtrlItemList;
                    if (child.Data.InternalId == allUiLists[i].InternalId)
                    {
                        wantedView = child;
                        break;
                    }
                }//for

                if (wantedView != null)
                {
                    // update the existing ones
                    wantedView.UpdateCtrlData(allUiLists[i]);
                }
                else
                {
                    CreateUIItem(allUiLists[i], i);
                }
            } //for
        }     //ProcessMessage
Ejemplo n.º 6
0
        public async Task <IActionResult> DeleteShoppingList(long listId)
        {
            ShoppingListDTO listToDelete = await shoppingListRepository.GetShoppingListByIdAsync(listId);

            if (listToDelete == null)
            {
                return(NotFound());
            }

            await shoppingListRepository.DeleteShoppingListAsync(listToDelete);

            return(Ok());
        }
Ejemplo n.º 7
0
        public async Task <IActionResult> Post([FromBody] CreateShoppingListDTO request)
        {
            var newProject = new ShoppingList(request.Name);

            var createdProject = await _repository.AddAsync(newProject);

            var result = new ShoppingListDTO
            {
                Id   = createdProject.Id,
                Name = createdProject.Name
            };

            return(Ok(result));
        }
Ejemplo n.º 8
0
        }//ListsManager

        public ShoppingListDTO CreateNewList()
        {
            lock (mLocker)
            {
                ShoppingListDTO newList = new ShoppingListDTO()
                {
                    ListDate   = DateTime.Now,
                    IsDirty    = true,
                    InternalId = Guid.NewGuid().ToString()
                };
                mStorage.ShLists.Add(newList);
                return(newList);
            } //lock
        }     //AddNewList
Ejemplo n.º 9
0
        public async Task <IActionResult> GetById(int id)
        {
            var shoppingListSpec = new ShoppingListByIdWithItemsSpec(id);
            var shoppingList     = await _repository.GetBySpecAsync(shoppingListSpec);

            var result = new ShoppingListDTO
            {
                Id    = shoppingList.Id,
                Name  = shoppingList.Name,
                Items = new List <ItemDTO>
                        (
                    shoppingList.Items.Select(i => ItemDTO.FromToDoItem(i)).ToList()
                        )
            };

            return(Ok(result));
        }
Ejemplo n.º 10
0
        public IHttpActionResult PutShoppingList(int clusterId, int id, ShoppingListDTO list)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            Cluster cluster = UnitOfWork.ClusterRepository.GetByID(clusterId);

            if (cluster == null)
            {
                return(NotFound());
            }
            else if (cluster.ApplicationUsers.FirstOrDefault(x => x.Id == UserRecord.Id) == null)
            {
                return(Unauthorized());
            }

            var entity = cluster.ShoppingLists.FirstOrDefault(x => x.Id == id);

            if (entity == null)
            {
                return(NotFound());
            }
            // Unable to modify a validated shopping list
            else if (entity.Validated == true)
            {
                return(BadRequest("Unable to modify a validated shopping list"));
            }

            entity.Name        = list.Name;
            entity.Description = list.Description;
            if (list.Validated == true && entity.Validated == false)
            {
                entity.ValidatedDate = DateTime.Now;
                // When validated, cluster is filled
                ValidateList(cluster, entity);
            }
            entity.Validated = list.Validated;

            UnitOfWork.ShoppingListRepository.Update(entity);
            UnitOfWork.Save();

            return(CreatedAtRoute("GetShoppingList", new { clusterId = clusterId, id = entity.Id }, Mapper.Map <GetShoppingListDTO>(entity)));
        }
Ejemplo n.º 11
0
        }     //AddNewList

        /// <summary>
        /// CreateListItem
        /// </summary>
        /// <param name="listInternalId"></param>
        /// <param name="description"></param>
        /// <param name="quantity"></param>
        /// <returns></returns>
        public ItemListDTO CreateListItem(string listInternalId, string description, int quantity)
        {
            ShoppingListDTO lst = GetListByInternalId(listInternalId);

            if (lst == null)
            {
                return(null);
            }

            lock (mLocker)
            {
                ItemListDTO item = new ItemListDTO();
                item.InternalId  = Guid.NewGuid().ToString();
                item.Quantity    = quantity;
                item.Description = description;

                lst.Items.Add(item);
                lst.IsDirty = true;
                return(item);
            }
        }//CreateListItem
Ejemplo n.º 12
0
        public async Task <IActionResult> UpdateShoppingList(long listId, ShoppingList listToUpdate)
        {
            if (listToUpdate == null)
            {
                return(BadRequest("You must provide a ShoppingList to update"));
            }

            if (listId == listToUpdate.ShoppingList_Id)
            {
                return(BadRequest("A matching list ID must be provided"));
            }

            ShoppingListDTO checkList = await shoppingListRepository.GetShoppingListByIdAsync(listId);

            if (checkList == null)
            {
                return(NotFound());
            }

            await shoppingListRepository.UpdateShoppingListAsync(dtoMapper.Map <ShoppingListDTO>(listToUpdate));

            return(Ok());
        }
Ejemplo n.º 13
0
 public void UpdateCtrlData(ShoppingListDTO aData)
 {
     m_Data     = aData;
     lstNm.Text = string.IsNullOrEmpty(m_Data.ListName) || m_Data.ListName.Contains(Constants.DEFAULT_LIST_NAME) ? ShAppContext.GetString(Resource.String.NewList) : m_Data.ListName;
     this.Invalidate();
 }
Ejemplo n.º 14
0
        public void ImportSyncData(string jsonHash, ResSyncDTO dto)
        {
            UpdateStorageHash(jsonHash);

            //delete those that are not returned
            List <string> idsLists = dto.listsMeta.items.Where(z => !string.IsNullOrEmpty(z.clientTag)).Select(x => x.clientTag).ToList();

            mStorage.ShLists.RemoveAll(x => !idsLists.Contains(x.InternalId) && !string.IsNullOrEmpty(x.Id)); //delete those that exists but not the new items that were just created


            dto.listsMeta.items.ForEach(L =>
            {
                ShoppingListDTO wantedlist = mStorage.ShLists.Where(x => x.InternalId == L.clientTag).FirstOrDefault();

                if (wantedlist == null)
                {
                    ShoppingListDTO newList = new ShoppingListDTO()
                    {
                        ListDate        = Tools.UnixTimeStampToDateTime(L.created),
                        IsDirty         = false,
                        InternalId      = Guid.NewGuid().ToString(),
                        Id              = L.id,
                        ListDescription = L.description,
                        ListName        = L.name
                    };

                    L.items.ForEach(I =>
                    {
                        ItemListDTO lstItem = new ItemListDTO(I);
                        newList.Items.Add(lstItem);
                    });

                    mStorage.ShLists.Add(newList);
                }//new one
                else
                {
                    //update list
                    wantedlist.Id = L.id;
                    wantedlist.ListDescription = L.description;
                    wantedlist.ListName        = L.name;

                    //delete listItems those that are not returned
                    List <string> lstItemsRet = L.items.Where(z => !string.IsNullOrEmpty(z.clientTag)).Select(x => x.clientTag).ToList();
                    wantedlist.Items.RemoveAll(x => !lstItemsRet.Contains(x.InternalId) && !string.IsNullOrEmpty(x.ProductId)); //delete those that exists but not the new items that were just created

                    L.items.ForEach(I =>
                    {
                        ItemListDTO wantedItem = wantedlist.Items.FirstOrDefault(x => x.InternalId == I.clientTag);
                        if (wantedItem == null)
                        {
                            wantedlist.Items.Add(new ItemListDTO(I));
                        }
                        else
                        {
                            wantedItem.Description = I.description;
                            wantedItem.ProductId   = I.productId;
                            wantedItem.Quantity    = I.quantity;
                            wantedItem.Bought      = (I.bought == 1);
                        }//else
                    });//items

                    wantedlist.IsDirty = false;//we did the sync
                }//else
            });
        }//ImportSyncData
Ejemplo n.º 15
0
        }//LoadLists

        private void AddNewList(object sender, EventArgs e)
        {
            ShoppingListDTO newList = ListsManager.Instance.CreateNewList();

            CreateUIList(newList);
        }//AddNewList
Ejemplo n.º 16
0
 public static ShoppingList MapToModel(this ShoppingListDTO source, IMapper mapper)
 {
     return(mapper.Map <ShoppingListDTO, ShoppingList>(source));
 }