public async Task <IActionResult> DeleteFunction(string id) { var function = await _context.Functions.FindAsync(id); if (function == null) { return(NotFound()); } _context.Functions.Remove(function); var result = await _context.SaveChangesAsync(); if (result > 0) { var fuctionVm = new FunctionVm() { Id = function.Id, Name = function.Name, Url = function.Url, SortOrder = function.SortOrder, ParentId = function.ParentId }; return(Ok(fuctionVm)); } return(BadRequest()); }
public async Task <IActionResult> DeleteFunction(string id) { var function = await _context.Functions.FindAsync(id); if (function == null) { return(NotFound(new ApiNotFoundResponse($"Cannot found function with id {id}"))); } _context.Functions.Remove(function); var commands = _context.CommandInFunctions.Where(x => x.FunctionId == id); _context.CommandInFunctions.RemoveRange(commands); var result = await _context.SaveChangesAsync(); if (result > 0) { var functionvm = new FunctionVm() { Id = function.Id, Name = function.Name, Url = function.Url, SortOrder = function.SortOrder, ParentId = function.ParentId, Icon = function.Icon }; return(Ok(functionvm)); } return(BadRequest(new ApiBadRequestResponse("Delete function failed"))); }
public static void UpdateFunction(this Function function, FunctionVm functionVm) { function.Id = functionVm.Id; function.Code = functionVm.Code; function.Description = functionVm.Description; function.CreatedBy = functionVm.CreatedBy; function.CreatedDate = functionVm.CreatedDate; }
public ActionResult Edit(FunctionVm functionVm) { if (ModelState.IsValid) { var function = new Function(); function.UpdateFunction(functionVm); _functionService.Update(function); _functionService.Save(); TempData["MessageSuccess"] = Message.EditSuccess; return(RedirectToAction("Index")); } TempData["MessageError"] = Message.CreateError; return(View()); }
public async Task <IActionResult> GetById(string id) { var function = await _context.Functions.FindAsync(id); if (function == null) { return(NotFound()); } var functionVm = new FunctionVm() { Id = function.Id, Name = function.Name, Url = function.Url, SortOrder = function.SortOrder, ParentId = function.ParentId }; return(Ok(functionVm)); }
public async Task <IActionResult> GetById(string id) { var function = await _context.Functions.FindAsync(id); if (function == null) { return(NotFound(new ApiNotFoundResponse($"Cannot found function with id {id}"))); } var functionVm = new FunctionVm() { Id = function.Id, Name = function.Name, Url = function.Url, SortOrder = function.SortOrder, ParentId = function.ParentId, Icon = function.Icon }; return(Ok(functionVm)); }
public async Task <IActionResult> GetById(string id) { //// GET FUNCTION WITH KEY INPUT var function = await _context.Functions.FindAsync(id); //// IF KEY NOT EXIST (FUNCTION IS NULL), RETURN STATUS IS 404 if (function == null) { return(NotFound(new ApiNotFoundResponse($"Cannot found function with id {id}"))); } //// GIVE INFO INTO FunctionVm (JUST SHOW NEEDED FIELD) var functionVm = new FunctionVm() { Id = function.Id, Name = function.Name, Url = function.Url, SortOrder = function.SortOrder, ParentId = function.ParentId }; return(Ok(functionVm)); }
public async Task <IActionResult> DeleteFunction(string id) { //// GET FUNCTION WITH ID (KEY). var function = await _context.Functions.FindAsync(id); //// IF KEY IS NOT EXIST (FUNCTION IS NULL), RETURN STATUS 404 if (function == null) { return(NotFound(new ApiNotFoundResponse($"Cannot found function with id {id}"))); } //// DELETE FUNCTION FROM DATASET (DATABASE INSTANCE) AND SAVE CHANGE _context.Functions.Remove(function); //// REMOVE COMMAND OF FUNCTION var commands = _context.CommandInFunctions.Where(x => x.FunctionId == id); _context.CommandInFunctions.RemoveRange(commands); var result = await _context.SaveChangesAsync(); //// IF RESULT AFTER DELETE IS GREATER THAN 0, DELETE SUCCESS AND RETURN STATUS 200 WITH INFO OF THIS FUNCTION //// ELSE RETURN STATUS 400 if (result > 0) { var functionvm = new FunctionVm() { Id = function.Id, Name = function.Name, Url = function.Url, SortOrder = function.SortOrder, ParentId = function.ParentId }; return(Ok(functionvm)); } return(BadRequest(new ApiBadRequestResponse("Delete function failed"))); }
public async Task <ActionResult <FunctionVm> > Get(long pempresa, string previsao, string pveiculoversao) { FunctionVm data = await Mediator.Send(new GetDataFromFunctionQuery { pempresa = pempresa, previsao = previsao, pveiculoversao = pveiculoversao }); return(data); }