Exemplo n.º 1
0
        public IActionResult Put(int id, [FromBody] Emotion emotion)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != emotion.EmotionId)
            {
                return(BadRequest());
            }

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

            try
            {
                _context.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!EmotionExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(new StatusCodeResult(StatusCodes.Status204NoContent));
        }
Exemplo n.º 2
0
        public IActionResult Post([FromBody] Image image)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            _context.Images.Add(image);
            try
            {
                _context.SaveChanges();
            }
            catch (DbUpdateException)
            {
                if (ImageExists(image.ImageId))
                {
                    return(new StatusCodeResult(StatusCodes.Status409Conflict));
                }
                else
                {
                    throw;
                }
            }

            return(CreatedAtRoute("GetImage", new { id = image.ImageId }, image));
        }
Exemplo n.º 3
0
        public IActionResult Post([FromBody] Taker taker)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }


            var existingUser = from g in _context.Takers
                               where g.TakerId == taker.TakerId
                               select g;

            if (existingUser.Count <Taker>() > 0)
            {
                return(new StatusCodeResult(StatusCodes.Status409Conflict));
            }


            _context.Takers.Add(taker);

            try
            {
                _context.SaveChanges();
            }
            catch (DbUpdateException)
            {
                if (TakerExists(taker.TakerId))
                {
                    return(new StatusCodeResult(StatusCodes.Status409Conflict));
                }
                else

                {
                    throw;
                }
            }

            return(CreatedAtRoute("GetTaker", new { id = taker.TakerId }, taker));
        }
Exemplo n.º 4
0
        public ActionResult Publish(AssetImages model)
        {
            if (!ModelState.IsValid)
            {
                return(View("Publish", model));
            }
            model.asset.Publisher   = User.Identity.Name;
            model.asset.ReleaseDate = DateTime.Now.ToString();
            if (!model.File.FileName.EndsWith("rar") && !model.File.FileName.EndsWith("zip"))
            {
                return(View("Publish", model));
            }
            string[] formats = new string[] { ".jpg", ".png", ".jpeg" };
            bool     Wrong   = true;

            foreach (var image in model.Files)
            {
                foreach (var item in formats)
                {
                    if (image.FileName.Contains(item))
                    {
                        Wrong = false;
                        break;
                    }
                }
            }
            if (Wrong)
            {
                return(View("Publish", model));
            }

            foreach (var file in model.Files)
            {
                if (file == null)
                {
                    //at least 1 photo per asset
                    return(View(model));
                }
                else if (file.ContentLength > 0)
                {
                    Picture c = new Picture();
                    c.ImageData = new byte[file.ContentLength];
                    file.InputStream.Read(c.ImageData, 0, c.ImageData.Length);

                    _photoContext.AssetsPhotos.Add(c);
                    _photoContext.SaveChanges();
                    if (model.asset.imagesId == null)
                    {
                        model.asset.imagesId = c.Id.ToString();
                    }
                    else
                    {
                        model.asset.imagesId += "," + c.Id.ToString();
                    }
                }
            }

            if (model.File.ContentLength > 0)
            {
                MemoryStream target = new MemoryStream();
                model.File.InputStream.CopyTo(target);
                byte[] data = target.ToArray();
                model.asset.assetZip = data;
            }
            model.asset.Size = model.asset.assetZip.Count() / 1048576f;

            //////
            if (model.asset.Type == "2D")
            {
                Asset2D asset2D = new Asset2D(model.asset);
                _context.Assets2D.Add(asset2D);
            }
            else if (model.asset.Type == "3D")
            {
                Asset3D asset3D = new Asset3D(model.asset);
                _context.Assets3D.Add(asset3D);
            }
            else if (model.asset.Type == "Audio")
            {
                AssetAudio assetAudio = new AssetAudio(model.asset);
                _context.AssetsAudio.Add(assetAudio);
            }
            else if (model.asset.Type == "Tools")
            {
                AssetTools assetTools = new AssetTools(model.asset);
                _context.AssetsTools.Add(assetTools);
            }
            else
            {
                return(HttpNotFound());
            }

            try
            {
                _context.SaveChanges();
            }
            catch (DbEntityValidationException e)
            {
                foreach (var eve in e.EntityValidationErrors)
                {
                    Debug.WriteLine("Entity of type \"{0}\" in state \"{1}\" has the following validation errors:",
                                    eve.Entry.Entity.GetType().Name, eve.Entry.State);
                    foreach (var ve in eve.ValidationErrors)
                    {
                        Debug.WriteLine("- Property: \"{0}\", Error: \"{1}\"",
                                        ve.PropertyName, ve.ErrorMessage);
                    }
                }
                Debug.WriteLine(model.asset.Type);
            }


            AllAssets allAssets = new AllAssets();

            allAssets.assets2D    = _context.Assets2D.ToList();
            allAssets.assets3D    = _context.Assets3D.ToList();
            allAssets.assetsAudio = _context.AssetsAudio.ToList();
            allAssets.assetsTools = _context.AssetsTools.ToList();

            return(RedirectToAction("Index", allAssets));
        }