Example #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());
        }
Example #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());
        }
Example #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"));
        }
Example #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));
        }
Example #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());
        }
Example #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());
        }
Example #7
0
        /// <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);
        }
Example #8
0
 public Element(string position, TypeOfGood goodType)
 {
     Position = position;
     GoodType = goodType;
 }