Exemplo n.º 1
0
        public IHttpActionResult PutCoupon(int id, Coupon coupon)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != coupon.CouponID)
            {
                return(BadRequest());
            }

            db.Entry(coupon).State = EntityState.Modified;

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!CouponExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
Exemplo n.º 2
0
        public bool CreateList(ListVM list)
        {
            try
            {
                OneListEntitiesCore db = new OneListEntitiesCore();
                //first, create List

                List newList = new List();

                newList.CreationDate = list.CreationDate;
                newList.CreatorID    = list.CreatorID;
                newList.ListName     = list.ListName;
                newList.ListTypeID   = list.ListTypeID;
                newList.ListStatusID = 1;

                List createdList = db.Lists.Add(newList);
                //then create list items and users
                db.SaveChanges();
                //list users
                string[] groups = list.SuscribergroupID.Split(',');
                foreach (string group in groups)
                {
                    ListUser Luser = new ListUser();
                    Luser.ListID           = createdList.ListID;
                    Luser.SuscriberGroupID = int.Parse(group);
                    Luser.SuscriptionDate  = list.CreationDate.ToShortDateString();

                    ListUser createdLuser = db.ListUsers.Add(Luser);
                    db.SaveChanges();
                }


                //listitems
                IEnumerable <Item> selectedItems = db.Items
                                                   .Where(a => a.ItemCategory == list.ItemCategoryID && a.UserID == list.CreatorID)
                                                   .Select(s => s);

                foreach (Item sel in selectedItems)
                {
                    ListItem lItem = new ListItem();
                    lItem.ItemID              = sel.ItemID;
                    lItem.ListID              = createdList.ListID;
                    lItem.ListItemSolved      = false;
                    lItem.ListItemSolvingDate = DateTime.Today;
                    db.ListItems.Add(lItem);
                }
                db.SaveChanges();
                return(true);
            }
            catch (Exception ex) {
                return(false);
            }
        }
Exemplo n.º 3
0
        /* *******************************************************
         * AddUserToGroup
         * Parameter: string userID
         ********************************************************/
        public void AddUserToGroup(SubscriberGroupVM subGroup, out string errMsg)
        {
            // TO DO: server side validation & client side validation
            var now = DateTime.UtcNow;
            OneListEntitiesCore db = new OneListEntitiesCore();

            SuscriberGroup     sGroup       = db.SuscriberGroups.Where(a => a.SuscriberGroupID == subGroup.SubscriberGroupID).FirstOrDefault();
            SuscriberGroupUser newGroupUser = new SuscriberGroupUser();

            newGroupUser.UserID           = subGroup.UserID;
            newGroupUser.SuscriberGroupID = subGroup.SubscriberGroupID;
            newGroupUser.UserTypeID       = DEFAULT_USER_TYPE;
            newGroupUser.ListUserStatus   = DEFAULT_STATUS;
            newGroupUser.SuscriptionDate  = now.ToShortDateString();
            newGroupUser.SuscriberGroup   = sGroup; //Add subscriberGroup property !important

            var query = db.SuscriberGroupUsers.Add(newGroupUser);
            SuscriberGroupUser existingUser = db.SuscriberGroupUsers
                                              .Where(a =>
                                                     a.SuscriberGroupID == subGroup.SubscriberGroupID &&
                                                     a.UserID == subGroup.UserID
                                                     ).FirstOrDefault();

            // Check if the user currently exist in the table
            if (existingUser == null)
            {
                db.SaveChanges();
                errMsg = "User Added.";
            }
            else
            {
                errMsg = "User Already Exist.";
            }
        }
Exemplo n.º 4
0
        public void DeleteItem(int itemId, out string errMsg)
        {
            OneListEntitiesCore db = new OneListEntitiesCore();
            Item itemToBeDeleted   = db.Items.Where(a => a.ItemID == itemId).FirstOrDefault();
            var  itemWithList      = db.ListItems
                                     .Where(l => l.ItemID == itemId)
                                     .FirstOrDefault();

            if (itemWithList != null)
            {
                errMsg = "Item used in list, cannot be deleted";
            }
            else
            {
                if (itemToBeDeleted != null)
                {
                    db.Items.Remove(itemToBeDeleted);
                    db.SaveChanges();
                    errMsg = "Item Deleted";
                }
                else
                {
                    errMsg = "Item could not be deleted.";
                }
            }
        }
Exemplo n.º 5
0
        public void CreateItem(ItemVM item)
        {
            //if (String.IsNullOrEmpty(item.ItemName))
            //{
            //    errMsg = "name field empty";
            //}else
            //{
            OneListEntitiesCore db = new OneListEntitiesCore();
            Item itemAdded         = new Item();

            itemAdded.UserID          = item.UserID;
            itemAdded.ItemName        = item.ItemName;
            itemAdded.ItemDescription = item.ItemDescription;
            itemAdded.ItemCategory    = (int)item.ItemCategory;

            //if (itemAdded.ItemCategory == 0)
            //{
            //    errMsg = "Items must belong to a category";
            //}
            //else {
            db.Items.Add(itemAdded);
            db.SaveChanges();
            //errMsg = "Item successfully added";
            //}
            //}
        }
Exemplo n.º 6
0
        public bool DeleteList(int List)
        {
            try
            {
                //items, users and then list
                OneListEntitiesCore db = new OneListEntitiesCore();
                //1.- first delete items.
                IEnumerable <ListItem> lItems = db.ListItems.Where(li => li.ListID == List).Select(p => p);
                db.ListItems.RemoveRange(lItems);
                //2.- remove users
                IEnumerable <ListUser> lUsers = db.ListUsers.Where(lu => lu.ListID == List).Select(p => p);
                db.ListUsers.RemoveRange(lUsers);
                //3.- finally Remove list
                List L = db.Lists.Where(l => l.ListID == List).Select(p => p).First();
                db.Lists.Remove(L);
                db.SaveChanges();
                return(true);
            }
            catch (Exception ex)
            {
                return(false);
            }

            return(true);
        }
Exemplo n.º 7
0
        public bool UpdateListData(int id, string name, int listType, int[] groups)
        {
            //update lists
            try
            {
                OneListEntitiesCore db = new OneListEntitiesCore();
                //first, select List

                List newList = db.Lists.Where(p => p.ListID == id).Select(r => r).FirstOrDefault();
                //change name
                newList.ListName = name;
                //change type
                newList.ListTypeID = listType;

                //last part,delete groups first, add them again

                IEnumerable <ListUser> currentGroups = db.ListUsers.Where(p => p.ListID == id).Select(r => r);
                db.ListUsers.RemoveRange(currentGroups);
                db.SaveChanges();
                foreach (int group in groups)
                {
                    ListUser Luser = new ListUser();
                    Luser.ListID           = id;
                    Luser.SuscriberGroupID = group;
                    Luser.SuscriptionDate  = DateTime.Today.ToShortDateString();

                    db.ListUsers.Add(Luser);
                    db.SaveChanges();
                }



                db.SaveChanges();
                return(true);
            }
            catch (Exception ex)
            {
                return(false);
            }


            return(true);
        }
Exemplo n.º 8
0
        public void CreateItemCategory(ItemCategoryVM itemCategory, string userID)
        {
            ItemCategory c = new ItemCategory();

            c.ItemCategoryName = itemCategory.ItemCategoryName;
            c.ItemCategoryID   = 0;
            c.UserID           = userID;
            OneListEntitiesCore Core = new OneListEntitiesCore();

            Core.ItemCategories.Add(c);
            Core.SaveChanges();
        }
Exemplo n.º 9
0
        public bool UpdateItem(ItemVM item)
        {
            OneListEntitiesCore db = new OneListEntitiesCore();
            Item itemUpdated       = db.Items.Where(a => a.ItemID == item.ItemID).FirstOrDefault();

            itemUpdated.ItemName        = item.ItemName;
            itemUpdated.ItemDescription = item.ItemDescription;
            itemUpdated.ItemCategory    = item.ItemCategory;

            db.SaveChanges();
            return(true);
        }
Exemplo n.º 10
0
        public bool UpdateItemCategory(ItemCategoryVM itemCategory)
        {
            OneListEntitiesCore db = new OneListEntitiesCore();
            ItemCategory        itemCategoryUpdated = db.ItemCategories
                                                      .Where(a =>
                                                             a.ItemCategoryID == itemCategory.ItemCategoryID
                                                             )
                                                      .FirstOrDefault();

            itemCategoryUpdated.ItemCategoryName = itemCategory.ItemCategoryName;
            db.SaveChanges();
            return(true);
        }
Exemplo n.º 11
0
 public bool deleteItemList(int itemID, int listID)
 {
     try
     {
         OneListEntitiesCore db = new OneListEntitiesCore();
         ListItem            l  = db.ListItems.Where(p => p.ItemID == itemID && p.ListID == listID).Select(r => r).First();
         db.ListItems.Remove(l);
         db.SaveChanges();
         return(true);
     }
     catch
     {
         return(false);
     }
 }
Exemplo n.º 12
0
 public ActionResult Edit(UserVM userInput)
 {
     if (userInput.FirstName != null && userInput.LastName != null)
     {
         OneListEntitiesCore db = new OneListEntitiesCore();
         User user = db.Users.Where(a => a.UserName == User.Identity.Name).FirstOrDefault();
         user.FirstName = userInput.FirstName;
         user.LastName  = userInput.LastName;
         db.SaveChanges();
         TempData["Success"] = "Updated successfully!";
     }
     else
     {
         TempData["Fail"] = "Failed to update!";
     }
     return(RedirectToAction("Index", "Profile"));
 }
Exemplo n.º 13
0
 public bool CompleteList(int id, string userID)
 {
     try
     {
         //items, users and then list
         OneListEntitiesCore db = new OneListEntitiesCore();
         //1.- complete list.
         List l = db.Lists.Where(p => p.ListID == id).Select(r => r).First();
         //change status to complete
         l.ListStatusID = COMPLETED;//completed
         db.SaveChanges();
         return(true);
     }
     catch (Exception ex)
     {
         return(false);
     }
 }
Exemplo n.º 14
0
        /* *******************************************************
         * UpdateGroup
         * Return: bool
         ********************************************************/
        public bool UpdateGroup(SubscriberGroupVM subscriberGroup)
        {
            try {
                OneListEntitiesCore db           = new OneListEntitiesCore();
                SuscriberGroup      groupUpdated = db.SuscriberGroups
                                                   .Where(a =>
                                                          a.SuscriberGroupID == subscriberGroup.SubscriberGroupID
                                                          ).FirstOrDefault();
                groupUpdated.SuscriberGroupName = subscriberGroup.SubscriberGroupName;
                db.SaveChanges();

                return(true);
            }

            catch (Exception ex)
            {
                return(false);
            }
        }
Exemplo n.º 15
0
        public ActionResult AddSubscriberGroup(SubscriberGroupVM subscriberGroup)
        {
            subscriberGroup.UserID = FindUserID();

            if (ModelState.IsValid)
            {
                SuscriberGroup sg = new SuscriberGroup();
                sg.SuscriberGroupName = subscriberGroup.SubscriberGroupName;
                sg.UserID             = subscriberGroup.UserID;
                OneListEntitiesCore Core = new OneListEntitiesCore();
                Core.SuscriberGroups.Add(sg);
                Core.SaveChanges();
            }
            else
            {
                ViewBag.ErrorMsg = "Cannot add Subscriber Group.";
            }
            return(View());
        }
Exemplo n.º 16
0
        /* *******************************************************
         * Change Subscriber Status
         * Void
         ********************************************************/
        public void ChangeSubscriberStatus(string userId, int id, out string errMsg)
        {
            OneListEntitiesCore db = new OneListEntitiesCore();
            SuscriberGroupUser  subscriberStatusToBeChanged = db.SuscriberGroupUsers
                                                              .Where(s =>
                                                                     s.UserID == userId &&
                                                                     s.SuscriberGroupID == id
                                                                     )
                                                              .FirstOrDefault();

            if (subscriberStatusToBeChanged != null)
            {
                subscriberStatusToBeChanged.ListUserStatus = GetStatusToBeChanged(subscriberStatusToBeChanged.ListUserStatus);
                db.SaveChanges();
                errMsg = "Subscriber Type Changed";
            }
            else
            {
                errMsg = "Subscriber type could not be changed.";
            }
        }
Exemplo n.º 17
0
        /* *******************************************************
         * DeleteSubscriber
         * Void
         ********************************************************/
        public void DeleteSubscriber(string userId, int id, out string errMsg)
        {
            OneListEntitiesCore db = new OneListEntitiesCore();
            SuscriberGroupUser  subscriberToBeDeleted = db.SuscriberGroupUsers
                                                        .Where(s =>
                                                               s.UserID == userId &&
                                                               s.SuscriberGroupID == id
                                                               )
                                                        .FirstOrDefault();

            if (subscriberToBeDeleted != null)
            {
                db.SuscriberGroupUsers.Remove(subscriberToBeDeleted);
                db.SaveChanges();
                errMsg = "Subscriber Deleted";
            }
            else
            {
                errMsg = "Subscriber could not be deleted.";
            }
        }
Exemplo n.º 18
0
        /* *******************************************************
         * Delete subscriber Group
         * Parameter: Int subscriberGroupId
         * Return: out errMsg (string)
         ********************************************************/
        public void DeleteGroup(string publisherID, int subscriberGroupId, out string errMsg)
        {
            OneListEntitiesCore db = new OneListEntitiesCore();
            SuscriberGroup      groupToBeUpdated = db.SuscriberGroups
                                                   .Where(s =>
                                                          s.SuscriberGroupID == subscriberGroupId
                                                          ).FirstOrDefault();
            int numOfSubscribers = db.SuscriberGroupUsers
                                   .Where(s =>
                                          s.SuscriberGroupID == subscriberGroupId
                                          ).Count();
            int numOfLists = db.ListUsers
                             .Where(l => l.SuscriberGroupID == subscriberGroupId)
                             .Count();

            if (numOfSubscribers > 0)
            {
                errMsg = "Group has subscribers and cannot be deleted";
            }
            else
            {
                if (numOfLists > 0)
                {
                    errMsg = "Group could not be deleted because it's used in lists.";
                }
                else
                {
                    if (groupToBeUpdated != null)
                    {
                        db.SuscriberGroups.Remove(groupToBeUpdated);
                        db.SaveChanges();
                        errMsg = "Group Deleted";
                    }
                    else
                    {
                        errMsg = "Group could not be deleted.";
                    }
                }
            }
        }
Exemplo n.º 19
0
        public bool updateItemList(string userID, int itemId, int id, bool solved, decimal cost, string notes)
        {
            try
            {
                //items, users and then list
                OneListEntitiesCore db = new OneListEntitiesCore();
                //1.- first delete items.
                ListItem l = db.ListItems.Where(d => d.ItemID == itemId && d.ListID == id).Select(g => g).First();
                l.ListItemSolved = solved;
                l.ListItemCost   = cost;
                l.ListItemNotes  = notes;
                l.ListItemSolver = userID;
                db.SaveChanges();
                return(true);
            }
            catch (Exception ex)
            {
                return(false);
            }

            return(true);
        }
Exemplo n.º 20
0
        public void DeleteItemCategory(int categoryID, out string errMsg)
        {
            OneListEntitiesCore db = new OneListEntitiesCore();
            ItemCategory        itemCategoryToBeDeleted = db.ItemCategories
                                                          .Where(a => a.ItemCategoryID == categoryID)
                                                          .FirstOrDefault();
            Item firstItemInCategory = db.Items
                                       .Where(a => a.ItemCategory == categoryID)
                                       .FirstOrDefault();
            var itemCategoryWithList = db.ListItems
                                       .Where(l => l.Item.ItemCategory == categoryID)
                                       .FirstOrDefault();

            if (itemCategoryWithList != null)
            {
                errMsg = "Item category used in list, cannot be deleted";
            }
            else
            {
                if (itemCategoryToBeDeleted != null)
                {
                    // check if there are items in this category
                    if (firstItemInCategory != null)
                    {
                        errMsg = "Item Category has items associated, cannot be deleted";
                    }
                    else
                    {
                        db.ItemCategories.Remove(itemCategoryToBeDeleted);
                        db.SaveChanges();
                        errMsg = "Item Category Deleted";
                    }
                }
                else
                {
                    errMsg = "Item Category could not be deleted.";
                }
            }
        }