public async Task <IActionResult> UpdateAsync(int id) { try { ProjectCaseModel model = await this.projectManagement.GetProjectCaseByIdAsync(id); if (model == null) { return(View("ErrorAdmin", new ErrorViewModel { Message = "Cannot get project! Something got wrong." })); } ProjectViewModel vModel = new ProjectViewModel(model); List <CategoryModel> categoryList = await this.categoryManagement.GetCategoryListAsync(DataAccess.Enums.CategoryType.Project).ConfigureAwait(false); ViewData["Categories"] = new SelectList(categoryList, nameof(CategoryModel.Id), nameof(CategoryModel.Name)); return(View("Update", vModel)); } catch (Exception ex) { return(View("ErrorAdmin", new ErrorViewModel { Message = ex.Message })); } }
public async Task <IActionResult> GetByIdAsync(int id) { try { ProjectCaseModel model = await this.projectManagement.GetProjectCaseByIdAsync(id); return(View("ProjectPage", model)); } catch (Exception ex) { return(View("Error", new ErrorViewModel { Message = ex.Message })); } }
public async Task <IActionResult> UpdateAsync(ProjectViewModel reqModel) { if (!ModelState.IsValid) { List <CategoryModel> categoryList = await this.categoryManagement.GetCategoryListAsync(DataAccess.Enums.CategoryType.Project).ConfigureAwait(false); ViewData["Categories"] = new SelectList(categoryList, nameof(CategoryModel.Id), nameof(CategoryModel.Name)); return(View("Update", reqModel)); } try { ProjectCaseModel model = reqModel.ToAppModel(); if (reqModel.ImageFile != null) { using (BinaryReader reader = new BinaryReader(reqModel.ImageFile.OpenReadStream())) { model.ImageFileName = reqModel.ImageFile.FileName; model.ImageMimeType = reqModel.ImageFile.ContentType; model.Image = reader.ReadBytes((int)reqModel.ImageFile.Length); } } ProjectCaseModel updatedModel = await this.projectManagement.UpdateProjectCaseAsync(model, this.appEnvironment.WebRootPath); if (model == null) { return(View("ErrorAdmin", new ErrorViewModel { Message = "Cannot updating project! Something got wrong." })); } return(RedirectToAction("", new { id = reqModel.Id })); } catch (Exception ex) { return(View("ErrorAdmin", new ErrorViewModel { Message = ex.Message })); } }
public async Task <ProjectCaseModel> GetProjectCaseByIdAsync(int projectId) { try { ProjectCase entity = await this.repo.GetProjectCaseAsync(projectId).ConfigureAwait(false); if (entity == null) { return(null); } ProjectCaseModel model = new ProjectCaseModel(); model.ToModel(entity); return(model); } catch { throw; } }
public async Task <IActionResult> GetByIdAsync(int id) { try { ProjectCaseModel model = await this.projectManagement.GetProjectCaseByIdAsync(id); if (model == null) { return(View("ErrorAdmin", new ErrorViewModel { Message = "Cannot get project! Something got wrong." })); } return(View("ProjectPage", model)); } catch (Exception ex) { return(View("ErrorAdmin", new ErrorViewModel { Message = ex.Message })); } }
public async Task <IActionResult> AddToCart(int id, int quantity = 1) { try { CartModel cart = this.GetCart(); ProjectCaseModel model = await this.projectManagement.GetProjectCaseByIdAsync(id); if (model != null) { CartLineModel existsItem = cart.Items.Where(i => i.ProjectCase.Id == id).FirstOrDefault(); if (existsItem != null) { existsItem.Quantity += quantity; } else { cart.Items.Add(new CartLineModel { ProjectCase = model, Quantity = quantity }); } cart = this.UpdateCart(cart); } TempData["ItemAdded"] = model != null; return(View("Cart", cart)); } catch (Exception ex) { return(View("Error", new ErrorViewModel { Message = ex.Message })); } }
public async Task <ProjectCaseModel> UpdateProjectCaseAsync(ProjectCaseModel model, string webRootFilePath) { model = model ?? throw new ArgumentNullException(nameof(model)); webRootFilePath = webRootFilePath ?? throw new ArgumentNullException(nameof(webRootFilePath)); try { ProjectCase entity = await this.repo.UpdateProjectCaseAsync(model.ToEntity(), webRootFilePath).ConfigureAwait(false); if (entity == null) { return(null); } ProjectCaseModel updatedModel = new ProjectCaseModel(); updatedModel.ToModel(entity); return(updatedModel); } catch { throw; } }
/// <summary> /// /// </summary> /// <param name="model"></param> /// <param name="fileFolderPath">Need folders {fileFolderPath}/Files/ProjectFiles</param> /// <returns></returns> public async Task <ProjectCaseModel> CreateProjectCaseAsync(ProjectCaseModel model, string fileFolderPath) { model = model ?? throw new ArgumentNullException(nameof(model)); fileFolderPath = fileFolderPath ?? throw new ArgumentNullException(nameof(fileFolderPath)); try { ProjectCase entity = await this.repo.CreateProjectCaseAsync(model.ToEntity(), fileFolderPath).ConfigureAwait(false); if (entity == null) { return(null); } ProjectCaseModel addedModel = new ProjectCaseModel(); addedModel.ToModel(entity); return(addedModel); } catch { throw; } }
public ProjectViewModel(ProjectCaseModel projectCaseModel) { this.Id = projectCaseModel.Id; this.ProjectName = projectCaseModel.ProjectName; this.Description = projectCaseModel.Description; }