Пример #1
0
        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
                }));
            }
        }
Пример #2
0
        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
                }));
            }
        }
Пример #3
0
        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
                }));
            }
        }
Пример #4
0
        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;
            }
        }
Пример #5
0
        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
                }));
            }
        }
Пример #6
0
        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
                }));
            }
        }
Пример #7
0
        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;
            }
        }
Пример #8
0
        /// <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;
            }
        }
Пример #9
0
 public ProjectViewModel(ProjectCaseModel projectCaseModel)
 {
     this.Id          = projectCaseModel.Id;
     this.ProjectName = projectCaseModel.ProjectName;
     this.Description = projectCaseModel.Description;
 }