예제 #1
0
        public async Task <IActionResult> PutBreeds(int id, Breeds breeds)
        {
            if (id != breeds.BreedId)
            {
                return(BadRequest());
            }

            _context.Entry(breeds).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!BreedsExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
        public ActionResult Edit(Itemadder it)
        {
            if (Session["swi"] == null)
            {
                return(RedirectToAction("Index", "Home"));
            }
            if (Session["swi"] != null && Session["isadmin"] == "no")
            {
                return(RedirectToAction("Index", "Customers"));
            }

            ViewBag.message = "";
            if (it.pv != null)
            {
                if (it.pv.Contains("") || it.pv.Contains(null))
                {
                    return(RedirectToAction("Index"));
                }
                try
                {
                    List <int> ignore = new List <int>();
                    int        id     = 0;
                    var        e      = from a in pdb.Properites
                                        select a;
                    foreach (var a in e)
                    {
                        id = a.P_Id;
                    }
                    Categories cat = new Categories(it.cat_name);
                    cat.Cat_Id          = it.cat_id;
                    db.Entry(cat).State = EntityState.Modified;
                    db.SaveChanges();

                    bool exist = false;
                    for (int i = 0; i < it.pv.Count; i++)
                    {
                        string x  = it.pv[i];
                        var    q1 = from a in pdb.Properites
                                    where a.P_Name.ToLower() == x.ToLower()
                                    select a;
                        foreach (var b in q1)
                        {
                            exist = true;
                            //Cat_pro cap = new Cat_pro();
                            //cap.Cat_Id = it.cat_id;
                            //cap.P_Id = b.P_Id;
                            //catpro.catpro.Add(cap);
                            ignore.Add(b.P_Id);
                        }
                        if (exist == false)
                        {
                            Properites p = new Properites(it.pv[i]);
                            id++;
                            p.P_Id = id;
                            ignore.Add(p.P_Id);
                            Cat_pro cap = new Cat_pro();
                            cap.Cat_Id = it.cat_id;
                            cap.P_Id   = p.P_Id;
                            catpro.catpro.Add(cap);
                            pdb.Properites.Add(p);
                        }
                    }


                    var ee = from a in catpro.catpro
                             where a.Cat_Id == it.cat_id
                             select a;

                    foreach (var t in ee)
                    {
                        if (ignore.Contains(t.P_Id))
                        {
                        }

                        else
                        {
                            Properites d2 = (from a in pdb.Properites where a.P_Name.ToLower() == "model" select a).First();
                            Properites d3 = (from a in pdb.Properites where a.P_Name.ToLower() == "date" select a).First();
                            Properites d4 = (from a in pdb.Properites where a.P_Name.ToLower() == "image" select a).First();
                            if (t.P_Id != d2.P_Id && t.P_Id != d3.P_Id && t.P_Id != d4.P_Id)
                            {
                                catpro.catpro.Remove(t);
                            }
                        }
                    }



                    /* Categories cat = new Categories(it.cat_name);
                     * cat.Cat_Id = it.cat_id;
                     * db.Entry(cat).State = EntityState.Modified;
                     * db.SaveChanges();*/



                    pdb.SaveChanges();
                    catpro.SaveChanges();
                    db.SaveChanges();

                    return(RedirectToAction("Index"));
                }
                catch { ViewBag.message = "INVALID ENTER"; return(View(it)); }
            }
            else
            {
                it.p   = new List <Properites>();
                it.pv  = new List <string>();
                it.ind = new List <int>();
                int counter = 0;

                it.item_name = it.cat_name;

                var q6 = from s in catpro.catpro
                         where s.Cat_Id == it.cat_id

                         select s;


                foreach (var d in q6)
                {
                    Properites ty = (from a in pdb.Properites where a.P_Id == d.P_Id select a).First();
                    if (ty.P_Name.ToLower() != "date" && ty.P_Name.ToLower() != "model" && ty.P_Name.ToLower() != "image")
                    {
                        counter++;
                        it.ind.Add(d.P_Id);
                    }
                }
                int y  = 0;
                var q5 = from s in pdb.Properites

                         select s;

                foreach (var a in q5)
                {
                    if (it.ind.Contains(a.P_Id))
                    {
                        it.p.Add(a);
                        it.pv.Add(a.P_Name);
                    }
                }


                ViewBag.number = counter;
                return(View(it));
            }
        }