コード例 #1
0
        public ActionResult Create(TypeOfGoodsVM v)
        {
            TypeOfGood t = new TypeOfGood();

            int max = (from d in db.TypeOfGoods orderby d.TypeOfGoodID descending select d.TypeOfGoodID).FirstOrDefault();

            if (max == null)
            {
                t.TypeOfGoodID = 1;
                t.TypeOfGood1  = v.TypeOfGood;
            }
            else
            {
                t.TypeOfGoodID = max + 1;
                t.TypeOfGood1  = v.TypeOfGood;
            }

            if (ModelState.IsValid)
            {
                db.TypeOfGoods.Add(t);
                db.SaveChanges();
                TempData["SuccessMsg"] = "You have successfully added Type Of Goods.";
                return(RedirectToAction("Index"));
            }

            return(View());
        }
コード例 #2
0
        public async Task <IActionResult> PutTypeOfGood(int id, TypeOfGood typeOfGood)
        {
            if (id != typeOfGood.Id)
            {
                return(BadRequest());
            }

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

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

            return(NoContent());
        }
コード例 #3
0
        public ActionResult DeleteConfirmed(int id)
        {
            TypeOfGood typeofgood = db.TypeOfGoods.Find(id);

            db.TypeOfGoods.Remove(typeofgood);
            db.SaveChanges();
            TempData["SuccessMsg"] = "You have successfully Deleted Type Of Goods.";
            return(RedirectToAction("Index"));
        }
コード例 #4
0
        //
        // GET: /TypeOfGood/Details/5

        public ActionResult Details(int id = 0)
        {
            TypeOfGood typeofgood = db.TypeOfGoods.Find(id);

            if (typeofgood == null)
            {
                return(HttpNotFound());
            }
            return(View(typeofgood));
        }
コード例 #5
0
        public async Task <ActionResult <TypeOfGood> > PostTypeOfGood(TypeOfGood typeOfGood)
        {
            if (_context.TypeOfGoods.Where(t => t.Name.ToLower() == typeOfGood.Name.ToLower()).Count() == 0)
            {
                _context.TypeOfGoods.Add(typeOfGood);
                await _context.SaveChangesAsync();

                return(CreatedAtAction("GetTypeOfGood", new { id = typeOfGood.Id }, typeOfGood));
            }
            return(NoContent());
        }
コード例 #6
0
        public ActionResult Edit(TypeOfGoodsVM data)
        {
            TypeOfGood v = new TypeOfGood();

            v.TypeOfGoodID = data.TypeOfGoodID;
            v.TypeOfGood1  = data.TypeOfGood;

            if (ModelState.IsValid)
            {
                db.Entry(v).State = EntityState.Modified;
                db.SaveChanges();
                TempData["SuccessMsg"] = "You have successfully Updated Type Of Goods.";
                return(RedirectToAction("Index"));
            }
            return(View());
        }
コード例 #7
0
ファイル: Program.cs プロジェクト: shaytan1986/positionreq
        /// <summary>
        /// Gets a specified number of fake Elements with a Guid for the Position, and a FinishedGoodType
        /// derived from the modulo of the current index
        /// </summary>
        /// <param name="mockCount">Number of mocks to generate</param>
        /// <returns></returns>
        public static IEnumerable <Element> GetMockElements(int mockCount = 20)
        {
            List <Element> elements = new List <Element>();
            int            enumSize = Enum.GetNames(typeof(TypeOfGood)).Length;

            for (int i = 0; i < mockCount; i++)
            {
                // evenly distribute the elements over the available mock types
                int        mockTypeIndex = i % enumSize;
                TypeOfGood mockType      = (TypeOfGood)mockTypeIndex;
                string     mockPosition  = Guid.NewGuid().ToString();

                elements.Add(new Element(mockPosition, mockType));
            }

            return(elements);
        }
コード例 #8
0
ファイル: Program.cs プロジェクト: shaytan1986/positionreq
 public Element(string position, TypeOfGood goodType)
 {
     Position = position;
     GoodType = goodType;
 }