예제 #1
0
        public async Task <ActionResult> Post([FromBody] ImagenHot model)
        {
            try
            {
                model.ImaId = 0;

                if (!model.ImaIsLink)
                {
                    var location = Path.Combine(_appSettings.PathImg, "hots");
                    var image    = Helpers.DataImage.TryParse(model.ImaPath);
                    var fileName = $"{Helpers.Utils.GenerateGuid()}.{image.Extesion}";

                    //Guardar Imagenes Fisicamente!.-
                    System.IO.File.WriteAllBytes(Path.Combine(location, fileName), image.RawData);

                    model.ImaPath = fileName;
                }
                _db.Add(model);

                await _db.SaveChangesAsync();

                return(Ok(model));
            }
            catch (Exception e)
            {
                return(BadRequest(e.Message));
            }
        }
예제 #2
0
        public async Task <ActionResult> Delete([FromBody] ImagenHot model)
        {
            try
            {
                _db.Remove(model);

                await _db.SaveChangesAsync();

                return(Ok(model));
            }
            catch (Exception e)
            {
                return(BadRequest(e.Message));
            }
        }