Пример #1
0
        internal bool UpdateProject(ProjectModel model, HttpRequestBase request)
        {
            if (request.Files["ProjectImage"].ContentLength > 0)
            {
                HttpPostedFileBase file = request.Files["ProjectImage"];
                string filePath = Path.Combine(HttpContext.Current.Server.MapPath("~/Content/uploads/projects/"), Path.GetFileName(file.FileName));
                file.SaveAs(filePath);
                model.ProjectImage = string.Format("\\Content\\uploads\\projects\\{0}", file.FileName);
                model.IsImageRemoved = false;
            }
            //IsImageRemoved is a hidden field has flag of whether image removed or not
            if (request.Files["ProjectImage"].ContentLength == 0 && model.IsImageRemoved)
            {
                model.ProjectImage = null;
            }

            if (!model.IsImageRemoved && request.Files["ProjectImage"].ContentLength == 0)
            {
                model.ProjectImage = projectsRepo.GetProjectImage(model.Id);
            }

            model.Description = HttpUtility.HtmlEncode(model.Description);
            model.IsVisible = true;
            Project Project = ProjectMapper.ProjectModelToProject(model);
            bool isUpdated = projectsRepo.Update(Project);
            return isUpdated;
        }
Пример #2
0
        public ActionResult Create(ProjectModel model)
        {
            ViewBag.ProjectStatusSelectList = GetProjectStatusSelectList();
            if (!ModelState.IsValid)
                return View(model);

            ProjectModel addedModel = projectBLL.AddProject(model, Request);
            return RedirectToAction("Create", new { status = ActionStatus.Success });
        }
Пример #3
0
        public ActionResult Modify(ProjectModel model)
        {
            ViewBag.ProjectStatusSelectList = GetProjectStatusSelectList();
            if (!ModelState.IsValid)
                return View(model);

            bool isUpdated = projectBLL.UpdateProject(model, Request);

            return RedirectToAction("Modify", new { status = ActionStatus.Success });

        }
Пример #4
0
 public static Project ProjectModelToProject(ProjectModel projectModel)
 {
     return new Project
     {
         Description = projectModel.Description,
         EndDate = projectModel.EndDate,
         Id = projectModel.Id,
         IsDeleted = projectModel.IsDeleted,
         Location = projectModel.Location,
         ProjectName = projectModel.ProjectName,
         StartDate = projectModel.StartDate,
         ProjectStatus = (int)projectModel.Status,
         ProjectImage = projectModel.ProjectImage,
         IsVisible = projectModel.IsVisible
     };
 }
Пример #5
0
        internal ProjectModel AddProject(ProjectModel model, HttpRequestBase request)
        {
            if (request.Files["ProjectImage"].ContentLength > 0)
            {
                HttpPostedFileBase file = request.Files["ProjectImage"];
                string filePath = Path.Combine(HttpContext.Current.Server.MapPath("~/Content/uploads/projects/"), Path.GetFileName(file.FileName));
                file.SaveAs(filePath);
                model.ProjectImage = string.Format("\\Content\\uploads\\projects\\{0}",file.FileName);
            }

            model.Description = HttpUtility.HtmlEncode(model.Description);
            model.IsVisible = true;
            Project Project = ProjectMapper.ProjectModelToProject(model);
            Project addedProject = projectsRepo.Add(Project);
            return ProjectMapper.ProjectToProjectModel(addedProject);
        }