public ActionResult Post([FromBody] NewProductDTO value)
        {
            int      id   = _context.GetMaxProductId() + 1;
            Category cat  = _context.GetCategoryByName(value.Category);
            Person   pers = _context.GetPerson(value.PersonEmail);

            if (pers == null)
            {
                return(BadRequest(value.PersonEmail));
            }

            float pric = 0;

            try
            {
                pric = float.Parse(value.Price, CultureInfo.InvariantCulture.NumberFormat);
            }
            catch
            {
                return(BadRequest(value.Price));
            }

            _context.Add(new WebshopData.Models.Product
            {
                Id          = id,
                ItemName    = value.ItemName,
                Description = value.Description,
                Price       = pric,
                UploadTime  = DateTime.Now,
                Category    = cat,
                Person      = pers
            });

            return(Ok());
        }
Example #2
0
        public IActionResult CreateNewEntry(string itemName,
                                            string description, string price, string CategoryKind)
        {
            int      id  = _context.GetMaxProductId() + 1;
            Category cat = _context.GetCategoryByName(CategoryKind);

            var email    = _authenticationService.GetLoggedUser().Key;
            var userName = _authenticationService.GetLoggedUser().Value;

            Person pers = _context.GetPerson(email);

            if (pers == null)
            {
                pers            = new Person();
                pers.Email      = email;
                pers.PersonName = userName;
            }

            float pric = 0;

            try
            {
                pric = float.Parse(price, CultureInfo.InvariantCulture.NumberFormat);
            }
            catch
            {
                //TODO: error handler must be implemented
            }

            _context.Add(new WebshopData.Models.Product
            {
                Id          = id,
                ItemName    = itemName,
                Description = description,
                Price       = pric,
                UploadTime  = DateTime.Now,
                Category    = cat,
                Person      = pers
            });

            return(RedirectToAction("Index"));
        }