public async Task <ServerResponse> Update(SaveApplicationViewModel model) { ServerResponse result; try { var entity = applicationRepository.GetById(model.Id); if (entity == null) { result = Utils.ErrorResponse(Constants.NOT_FOUND, model.Id); } else { entity = ModelFormatter.FormatApplicationModel(model, entity); entity = await applicationRepository.Update(entity); result = Utils.SuccessResponse(entity.Id); } } catch (Exception ex) { result = Utils.ErrorResponse(ex.ToString()); } return(result); }
public async Task <ServerResponse> Save(SaveApplicationViewModel model) { ServerResponse result; try { model.Id = 0; var entity = ModelFormatter.FormatApplicationModel(model); entity = await applicationRepository.Save(entity); result = Utils.SuccessResponse(entity.Id); } catch (Exception ex) { result = Utils.ErrorResponse(ex.ToString()); } return(result); }
/// <summary> /// Format ApplicationViewModel to Application model /// </summary> public static Infrastructure.DataContext.Application FormatApplicationModel(SaveApplicationViewModel model, Infrastructure.DataContext.Application modelDB = null) { if (modelDB == null) { modelDB = new Infrastructure.DataContext.Application() { Id = model.Id, Name = model.Name, CreatedDate = Utils.GetCurrentDateTime(), LastUpdatedDate = Utils.GetCurrentDateTime(), IdStatus = model.IdStatus }; } else { modelDB.Name = model.Name; modelDB.LastUpdatedDate = Utils.GetCurrentDateTime(); modelDB.IdStatus = model.IdStatus; } return(modelDB); }
public async Task <IActionResult> Update(SaveApplicationViewModel model) { var result = await applicationService.Update(model); return(Ok(result)); }