public IActionResult Delete([FromBody] DeleteCatalogViewModel model)
        {
            string token = "";

            if (HttpContext.Request.Headers != null)
            {
                token = HttpContext.Request.Headers[HeaderNames.Authorization].ToString();
            }

            if (string.IsNullOrWhiteSpace(token) == false && token.StartsWith("Bearer ", StringComparison.OrdinalIgnoreCase))
            {
                token = token.Substring("Bearer ".Length).Trim();
            }
            else
            {
                return(Unauthorized());
            }

            var jwtToken = new JwtSecurityTokenHandler().ReadJwtToken(token);
            int userId   = Convert.ToInt32(jwtToken.Claims.ToList()[2].Value);

            if (userId != model.CustIdMain)
            {
                return(Forbid());
            }
            var newCatalog = mapper.Map <Catalog>(model);
            var res        = repo.Delete(newCatalog);

            return(Ok(res));
        }
Example #2
0
        public IActionResult Delete(int id)
        {
            var catalog = _catalogRepository.GetById(id);

            _catalogRepository.Delete(catalog);

            return(RedirectToAction("List"));
        }
Example #3
0
        public async Task <ActionResult> Delete(long id)
        {
            try
            {
                await _catalog.Delete(id);
            }
            catch (Exception) when(!CatalogExists(id))
            {
                return(NotFound());
            }

            return(Ok());
        }
Example #4
0
        // ============ Methods to REMOVE something ============

        /**
         * Method that will soft-delete the catalog with the passed reference OR return all the errors found when trying to do so.
         *
         * Validations performed:
         * 1. Validation of the passed catalog's reference (database);
         */
        public ValidationOutput Remove(string refer)
        {
            //1.
            ValidationOutput validationOutput = new ValidationOutputNotFound();

            if (!CatalogExists(refer))
            {
                validationOutput.AddError("Reference of catalog", "No catalog with the reference '" + refer + "' exists in the system.");
                return(validationOutput);
            }

            Catalog catalogToRemove = _catalogRepository.GetByReference(refer);

            _catalogRepository.Delete(catalogToRemove);
            return(validationOutput);
        }
Example #5
0
 public ActionResult Delete(int id)
 {
     try
     {
         int totalRecord = 0;
         var obj         = _userRepository.Delete(id);
         if (obj)
         {
             var model = _userRepository.GetLst(new catalog(), 1, NumberRecord, out totalRecord);
             return(Json(new { err = true, view = RenderRazorViewToString(ControllerContext, "LstView", model) }));
         }
         else
         {
             return(Json(new { err = false, msg = "Dữ liệu không tồn tại!" }));
         }
     }
     catch (Exception ex)
     {
         return(Json(new { err = false, msg = ex.ToString() }));
     }
 }
Example #6
0
 internal void Delete(CatalogEntry entry)
 {
     _catalogRepository.Delete(entry);
 }