Ejemplo n.º 1
0
        public async Task <IActionResult> Create([Bind(properties)] GoodView c, IFormFile file)
        {
            if (!ModelState.IsValid)
            {
                return(View(c));
            }

            var(imgData, imgName) = FileHelper.ParseImageToBytes(file);

            c.ID   = Guid.NewGuid().ToString();
            c.Code = GetRandom.Code();
            await changeCodeIfInUse(c.Code, c);

            await validateId(c.ID, ModelState);

            var o = GoodFactory.Create(c.ID, c.Name, c.Code, c.Description, c.Price, c.Type,
                                       imgData, imgName);

            await repository.AddObject(o);

            return(RedirectToAction("Index"));
        }