public ActionResult AddScope(ScopeDTO scopeDto)
        {
            using (var db = new GunStoreContext())
            {
                if (ModelState.IsValid)
                {
                    var scope = new Scope()
                    {
                        Name        = scopeDto.Name,
                        Description = scopeDto.Description,
                        Price       = scopeDto.Price,
                        Quantity    = scopeDto.Quantity,
                    };
                    if (scopeDto.Image != null)
                    {
                        scope.Image = new byte[scopeDto.Image.ContentLength];
                        scopeDto.Image.InputStream.Read(scope.Image, 0, scopeDto.Image.ContentLength);
                    }

                    db.Scopes.Add(scope);
                    db.SaveChanges();
                    ModelState.Clear();
                    return(RedirectToAction("AddProduct", "Admin"));
                }
                ModelState.AddModelError("scope", "Invalid scope added");
                return(View());
            }
        }
 public async Task <ResponseServiceDTO> Update(ScopeDTO scopeDTO)
 {
     throw new NotImplementedException();
 }
예제 #3
0
 public static ApiScope ToEntity(this ScopeDTO dto)
 {
     return(dto == null ? null : Mapper.Map <ApiScope>(dto));
 }