Example #1
0
 public ActionResult StickerSell(ViewModelStick model, string name = "")
 {
     if (ModelState.IsValid)
     {
         var sticker = db.Stickers.Find(model.TheSticker.İD);
         if (sticker.Status != model.TheSticker.Status)
         {
             //eger status true onda ev satilmiw hesab olunnur ve bazaya elave olunur
             if (model.TheSticker.Status == true)
             {
                 int  userId = db.Users.Where(x => x.UserName == User.Identity.Name).FirstOrDefault().ID;
                 Sell sell   = new Sell
                 {
                     Name     = name,
                     Stick_ID = model.TheSticker.İD,
                     Users_Id = userId,
                     Price    = sticker.Price
                 };
                 db.Sells.Add(sell);
                 db.SaveChanges();
                 sticker.Status          = model.TheSticker.Status;
                 db.Entry(sticker).State = EntityState.Modified;
                 db.SaveChanges();
             }
             //false ede bilmez ona gore else yoxdu
         }
     }
     return(RedirectToAction("Edit", new { id = model.TheSticker.İD }));
 }
Example #2
0
        // GET: Admin/Stickers/Create
        public ActionResult Create()
        {
            //ViewBag.Project_İD = new SelectList(db.Projects, "İD", "Name");
            //ViewBag.Type_İD = new SelectList(db.Stick_Type, "İD", "Name");
            ViewModelStick model = new ViewModelStick {
                PProject = db.Projects.ToList(), SStick_Type = db.Stick_Type.ToList()
            };

            return(View(model));
        }
Example #3
0
        public ActionResult Create(/*[Bind(Include = "İD,Name,Project_İD,Price,Short_info,Type_İD,Area,GarageStatus,Status,fileModel.files")]*/ ViewModelStick sticker)
        {
            if (ModelState.IsValid)
            {
                sticker.TheSticker.Status = false;

                db.Stickers.Add(sticker.TheSticker);
                db.SaveChanges();
                return(RedirectToAction("Edit", new { id = sticker.TheSticker.İD }));
            }
            foreach (var item in sticker.TheSticker.fileModels.files)
            {
                var FileName = Path.GetFileName(item.FileName);
                var path     = Path.Combine(Server.MapPath("/Public/images/"), FileName);
                item.SaveAs(path);

                db.Stick_Photo.Add(new Stick_Photo {
                    Name = "/Public/images/" + FileName, Sticker = sticker.TheSticker
                });
                db.SaveChanges();
            }
            foreach (var itemSxem in sticker.TheSticker.fileModelsxem.files)
            {
                var FileNameSxem = Path.GetFileName(itemSxem.FileName);
                var path         = Path.Combine(Server.MapPath("/Public/images/"), FileNameSxem);
                itemSxem.SaveAs(path);

                db.Stick_sxem.Add(new Stick_sxem {
                    Name = "/Public/images/" + FileNameSxem, Sticker = sticker.TheSticker
                });
                db.SaveChanges();
            }



            ViewBag.Project_İD = new SelectList(db.Projects, "İD", "Name", sticker.TheSticker.Project_İD);
            ViewBag.Type_İD    = new SelectList(db.Stick_Type, "İD", "Name", sticker.TheSticker.Type_İD);
            return(View(sticker));
        }
Example #4
0
        public ActionResult Edit(ViewModelStick model, string type, string prtype, string name = "")
        {
            if (ModelState.IsValid)
            {
                model.TheSticker.Project_İD = Convert.ToInt32(prtype);
                model.TheSticker.Type_İD    = Convert.ToInt32(type);

                if (User.IsInRole("Administrator"))
                {
                    foreach (var item in model.fileModels.files)
                    {
                        if (item != null)
                        {
                            var FileName = Path.GetFileName(item.FileName);
                            var path     = Path.Combine(Server.MapPath("/Public/images/"), FileName);
                            item.SaveAs(path);

                            db.Stick_Photo.Add(new Stick_Photo {
                                Name = "/Public/images/" + FileName, Stick_İD = model.TheSticker.İD
                            });
                            db.SaveChanges();
                        }
                    }

                    foreach (var item in model.fileModelsxem.files)
                    {
                        if (item != null)
                        {
                            var FileNameSxem = Path.GetFileName(item.FileName);
                            var path         = Path.Combine(Server.MapPath("/Public/images/"), FileNameSxem);
                            item.SaveAs(path);

                            db.Stick_sxem.Add(new Stick_sxem {
                                Name = "/Public/images/" + FileNameSxem, Stick_Id = model.TheSticker.İD
                            });
                            db.SaveChanges();
                        }
                    }
                    var status = db.Stickers.AsNoTracking().Where(x => x.İD == model.TheSticker.İD).FirstOrDefault().Status;
                    int userId = db.Users.Where(x => x.UserName == User.Identity.Name).FirstOrDefault().ID;
                    if (status != model.TheSticker.Status)
                    {
                        //eger statusun false edirse demeli sell bazasinda silirem
                        if (model.TheSticker.Status == false)
                        {
                            Sell sl = db.Sells.Where(x => x.Stick_ID == model.TheSticker.İD).FirstOrDefault();
                            db.Sells.Remove(sl);
                        }
                        else if (model.TheSticker.Status == true)
                        {
                            Sell sell = new Sell
                            {
                                Name     = name,
                                Stick_ID = model.TheSticker.İD,
                                Users_Id = userId,
                                Price    = model.TheSticker.Price
                            };
                            db.Sells.Add(sell);
                            db.SaveChanges();
                        }
                    }
                    db.Entry(model.TheSticker).State = EntityState.Modified;
                    db.SaveChanges();
                }
                else if (User.IsInRole("Editor"))
                {
                    var sticker = db.Stickers.AsNoTracking().Where(x => x.İD == model.TheSticker.İD).FirstOrDefault();
                    model.TheSticker.Status          = sticker.Status;
                    db.Entry(model.TheSticker).State = EntityState.Modified;
                    db.SaveChanges();
                }
                return(RedirectToAction("Index"));
            }
            return(View(model));
        }