예제 #1
0
        public HttpResponseMessage Create(PortifolioItem item)
        {
            var response = new HttpResponseMessage();

            try
            {
                item = _service.PortifolioItem.Create(item);
                response = Request.CreateResponse(HttpStatusCode.OK, item);
            }
            catch (Exception ex)
            {
                response = Request.CreateErrorResponse(HttpStatusCode.BadRequest, ex.Message);
            }

            return response;
        }
예제 #2
0
        public IActionResult Edit(Guid id, PortifolioViewModel model)
        {
            if (id != model.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    if (model.File != null)
                    {
                        string uploads  = Path.Combine(_hosting.WebRootPath, @"img\portfolio");
                        string FullPath = Path.Combine(uploads, model.File.FileName);
                        model.File.CopyTo(new FileStream(FullPath, FileMode.Create));
                    }
                    PortifolioItem portifolioItem = new PortifolioItem
                    {
                        Id          = model.Id,
                        Projectname = model.Projectname,
                        Description = model.Description,
                        ImageUrl    = model.File.FileName,
                    };
                    _porifolio.Entity.Update(portifolioItem);
                    _porifolio.Save();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!PortifolioItemExists(model.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(model));
        }
예제 #3
0
 public async Task <IActionResult> Create(PortifolioViewModel model)
 {
     if (ModelState.IsValid)
     {
         if (model.File != null)
         {
             string uploads  = Path.Combine(_hosting.WebRootPath, @"img\portfolio");
             string FullPath = Path.Combine(uploads, model.File.FileName);
             model.File.CopyTo(new FileStream(FullPath, FileMode.Create));
         }
         PortifolioItem portifolioItem = new PortifolioItem
         {
             Projectname = model.Projectname,
             Description = model.Description,
             ImageUrl    = model.File.FileName,
         };
         _porifolio.Entity.Insert(portifolioItem);
         _porifolio.Save();
         return(RedirectToAction(nameof(Index)));
     }
     return(View(model));
 }