public ActionResult Edit([Bind(Include = "ItemPostId,ItemCategoryId_,LocationId_,ItemName,PhoneNumber,EmailAddress_,Quantity,Description,Photo1,Photo2,Photo3,UserTypeId,CreatedOn,ModifiedOn,ItemStatusId,ContactByEmail,ContactByPhone,DisplayMyPhoneNo,DisplayMyEmail_,ItemCollectPreferenceId")] ItemPost itempost)
        {
            if (ModelState.IsValid)
            {
                itempost.UserId          = GetUserId(itempost);
                db.Entry(itempost).State = EntityState.Modified;
                db.SaveChanges();

                string toAddress = itempost.EmailAddress_.ToString();
                string subject   = "DonateForGood: " + itempost.ItemName.ToString();
                string body      = string.Empty;

                string pageURL = System.Web.HttpContext.Current.Request.Url.ToString();
                pageURL = pageURL.Replace("Create", string.Empty);
                string EditURL   = pageURL + "Edit/" + itempost.ItemPostId.ToString();
                string DeleteURL = pageURL + "Delete/" + itempost.ItemPostId.ToString();
                body = "Please click on these links if you want to <a href='" + EditURL + "'>EDIT</a>  OR <a href='" + DeleteURL + "'>DELETE</a> your item post from DonateForGood website";

                if (SendMail(toAddress, subject, body) == "Successful")
                {
                    return(RedirectToAction("Index", "Home"));
                }
                return(RedirectToAction("Index", "Home"));
            }
            ViewBag.ItemCategoryId_         = new SelectList(db.ItemCategories, "ItemCategoryId", "ItemCategoryName", itempost.ItemCategoryId_);
            ViewBag.ItemCollectPreferenceId = new SelectList(db.ItemCollectPreferences, "ItemCollectPreferenceId", "ItemCollectPreferenceName", itempost.ItemCollectPreferenceId);
            ViewBag.LocationId_             = new SelectList(db.Locations, "LocationId", "LocationName", itempost.LocationId_);
            ViewBag.ItemStatusId            = new SelectList(db.ItemStatus, "ItemStatusId", "ItemStatusName", itempost.ItemStatusId);
            return(View(itempost));
        }
Exemple #2
0
        public void urlImg(String urlI)
        {
            info.Text = "Imagen subida";
            this.urlI = urlI;
            SolidColorBrush brush = new SolidColorBrush();

            brush.Color   = Color.FromArgb(0xff, 0, 0, 0);
            newImage.Fill = brush;

            //*ItemPost*//
            try
            {
                ItemPost newPost = new ItemPost()
                {
                    Place        = NewPlace.Text,
                    Product      = newProduct.Text,
                    Usuario      = PhoneApplicationService.Current.State["Username"].ToString(),
                    ImageProduct = urlI,
                    Time         = DateTime.Now.ToShortDateString(),
                    CoordPlace   = place
                };
                itemPostMongo.insertDocument(newPost);
                MessageBox.Show("Recomendación publicada", "¡Aviso!", MessageBoxButton.OK);
                NavigationService.Navigate(new Uri("/Main.xaml", UriKind.Relative));
            }
            catch (Exception)
            {
                MessageBox.Show("Compruebe la conexión a internet", "Error de conexión", MessageBoxButton.OK);
                throw;
            }
        }
        public JsonResult PostItem([FromBody] ItemPost itemPost)
        {
            try
            {
                Item  item   = itemPost.item;
                int[] tagIds = itemPost.tagIds;
                if (item is not null)
                {
                    db.Items.Add(item);
                    db.SaveChanges();

                    if (tagIds.Length != 0)
                    {
                        int item_id = item.id;
                        for (int i = 0; i < tagIds.Length; i++)
                        {
                            db.ItemsTags.Add(new ItemsTag()
                            {
                                item_id = item_id,
                                tag_id  = tagIds[i]
                            });
                        }
                        db.SaveChanges();
                    }
                }
                return(Json(item));
            }
            catch (SqlException e)
            {
                return(Json(e.Message));
            }
        }
        public ActionResult DeleteConfirmed(int id)
        {
            ItemPost itempost = db.ItemPosts.Find(id);

            db.ItemPosts.Remove(itempost);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
        public ActionResult Create([Bind(Include = "ItemPostId,ItemCategoryId_,LocationId_,ItemName,PhoneNumber,EmailAddress_,Quantity,Description,Photo1,Photo2,Photo3,UserTypeId,CreatedOn,ModifiedOn,ItemStatusId,ContactByEmail,ContactByPhone,DisplayMyPhoneNo,DisplayMyEmail_,ItemCollectPreferenceId")] ItemPost itempost)
        {
            if (ModelState.IsValid)
            {
                DonateForGood.Models.User user = new Models.User
                {
                    UserTypeId   = 2,
                    PhoneNumber  = itempost.PhoneNumber,
                    EmailAddress = itempost.EmailAddress_
                };
                int userId = 0;
                var query  = (from tableUser in db.Users
                              where (tableUser.PhoneNumber == user.PhoneNumber || tableUser.EmailAddress == user.EmailAddress)
                              select tableUser.UserId);
                if (!(query.Any()))
                {
                    db.Users.Add(user);
                    db.SaveChanges();
                    userId = (from tableUser in db.Users
                              where (tableUser.PhoneNumber == user.PhoneNumber || tableUser.EmailAddress == user.EmailAddress)
                              select tableUser.UserId).First();
                }
                else
                {
                    userId = (from tableUser in db.Users
                              where (tableUser.PhoneNumber == user.PhoneNumber || tableUser.EmailAddress == user.EmailAddress)
                              select tableUser.UserId).First();
                }

                itempost.UserId = userId;
                db.ItemPosts.Add(itempost);
                db.SaveChanges();

                string toAddress = itempost.EmailAddress_.ToString();
                string subject   = "DonateForGood: " + itempost.ItemName.ToString();
                string body      = string.Empty;

                string pageURL = System.Web.HttpContext.Current.Request.Url.ToString();
                pageURL = pageURL.Replace("Create", string.Empty);
                string EditURL   = pageURL + "Edit/" + itempost.ItemPostId.ToString();
                string DeleteURL = pageURL + "Delete/" + itempost.ItemPostId.ToString();
                body = "Please click on these links if you want to <a href='" + EditURL + "'>EDIT</a>  OR <a href='" + DeleteURL + "'>DELETE</a> your item post from DonateForGood website";

                if (SendMail(toAddress, subject, body) == "Successful")
                {
                    return(RedirectToAction("Index"));
                }
            }
            ViewBag.ItemCategoryId_         = new SelectList(db.ItemCategories, "ItemCategoryId", "ItemCategoryName", itempost.ItemCategoryId_);
            ViewBag.ItemCollectPreferenceId = new SelectList(db.ItemCollectPreferences, "ItemCollectPreferenceId", "ItemCollectPreferenceName", itempost.ItemCollectPreferenceId);
            ViewBag.LocationId_             = new SelectList(db.Locations, "LocationId", "LocationName", itempost.LocationId_);
            ViewBag.ItemStatusId            = new SelectList(db.ItemStatus, "ItemStatusId", "ItemStatusName", itempost.ItemStatusId);
            return(View(itempost));
        }
        // GET: /Item/Delete/5
        public ActionResult Delete(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            ItemPost itempost = db.ItemPosts.Find(id);

            if (itempost == null)
            {
                return(HttpNotFound());
            }
            return(View(itempost));
        }
 public ActionResult Edit([Bind(Include = "ItemPostId,ItemCategoryId_,LocationId_,ItemName,PhoneNumber,EmailAddress_,Quantity,Description,Photo1,Photo2,Photo3,UserTypeId,CreatedOn,ModifiedOn,ItemStatusId,ContactByEmail,ContactByPhone,DisplayMyPhoneNo,DisplayMyEmail_,ItemCollectPreferenceId")] ItemPost itempost)
 {
     if (ModelState.IsValid)
     {
         db.Entry(itempost).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.ItemCategoryId_         = new SelectList(db.ItemCategories, "ItemCategoryId", "ItemCategoryName", itempost.ItemCategoryId_);
     ViewBag.ItemCollectPreferenceId = new SelectList(db.ItemCollectPreferences, "ItemCollectPreferenceId", "ItemCollectPreferenceName", itempost.ItemCollectPreferenceId);
     ViewBag.LocationId_             = new SelectList(db.Locations, "LocationId", "LocationName", itempost.LocationId_);
     ViewBag.ItemStatusId            = new SelectList(db.ItemStatus, "ItemStatusId", "ItemStatusName", itempost.ItemStatusId);
     return(View(itempost));
 }
        public ActionResult Details(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            TempData["Id"] = id;
            ItemPost itempost = db.ItemPosts.Find(id);

            if (itempost == null)
            {
                return(HttpNotFound());
            }
            return(View(itempost));
        }
        // GET: /Item/Edit/5
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            ItemPost itempost = db.ItemPosts.Find(id);

            if (itempost == null)
            {
                return(HttpNotFound());
            }
            ViewBag.ItemCategoryId_         = new SelectList(db.ItemCategories, "ItemCategoryId", "ItemCategoryName", itempost.ItemCategoryId_);
            ViewBag.ItemCollectPreferenceId = new SelectList(db.ItemCollectPreferences, "ItemCollectPreferenceId", "ItemCollectPreferenceName", itempost.ItemCollectPreferenceId);
            ViewBag.LocationId_             = new SelectList(db.Locations, "LocationId", "LocationName", itempost.LocationId_);
            ViewBag.ItemStatusId            = new SelectList(db.ItemStatus, "ItemStatusId", "ItemStatusName", itempost.ItemStatusId);
            return(View(itempost));
        }
        public int GetUserId(ItemPost itempost)
        {
            int userId = 0;

            if (Session["LoggedInUserId"] != null)
            {
                userId = int.Parse(Session["LoggedInUserId"].ToString());
            }
            if (userId == 0)
            {
                string[] email    = itempost.EmailAddress_.Split('@');
                string   username = email[0];
                DonateForGood.Models.User user = new Models.User
                {
                    UserTypeId   = 2,
                    PhoneNumber  = itempost.PhoneNumber,
                    EmailAddress = itempost.EmailAddress_,
                    UserName     = username
                };
                var query = (from tableUser in db.Users
                             where (tableUser.PhoneNumber == user.PhoneNumber || tableUser.EmailAddress == user.EmailAddress)
                             select tableUser.UserId);
                if (!(query.Any()))
                {
                    db.Users.Add(user);
                    db.SaveChanges();
                    userId = (from tableUser in db.Users
                              where (tableUser.PhoneNumber == user.PhoneNumber || tableUser.EmailAddress == user.EmailAddress)
                              select tableUser.UserId).First();
                }
                else
                {
                    userId = (from tableUser in db.Users
                              where (tableUser.PhoneNumber == user.PhoneNumber || tableUser.EmailAddress == user.EmailAddress)
                              select tableUser.UserId).First();
                }
            }
            return(userId);
        }
        // GET: /Item/Edit/5
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            ItemPost itempost = db.ItemPosts.Find(id);

            if (itempost == null)
            {
                return(HttpNotFound());
            }
            ViewBag.ItemCategoryId_         = new SelectList(db.ItemCategories, "ItemCategoryId", "ItemCategoryName", itempost.ItemCategoryId_);
            ViewBag.LocationId_             = new SelectList(db.Locations, "LocationId", "LocationName", itempost.LocationId_);
            ViewBag.ItemName                = itempost.ItemName;
            ViewBag.PhoneNumber             = itempost.PhoneNumber;
            ViewBag.EmailAddress            = itempost.EmailAddress_;
            ViewBag.Quantity                = itempost.Quantity;
            ViewBag.Description             = itempost.Description;
            ViewBag.ItemCollectPreferenceId = new SelectList(db.ItemCollectPreferences, "ItemCollectPreferenceId", "ItemCollectPreferenceName", itempost.ItemCollectPreferenceId);
            ViewBag.ItemStatusId            = new SelectList(db.ItemStatus, "ItemStatusId", "ItemStatusName", itempost.ItemStatusId);
            return(View(itempost));
        }