예제 #1
0
        public ActionResult UpdatePhoto(PhotoPO form)
        {
            ActionResult response = null;

            if (Session["RoleID"] != null && (byte)Session["RoleId"] == 3)
            {
                if (ModelState.IsValid)
                {
                    try
                    {
                        _dataAccess.UpdatePhoto(PhotoMapper.PhotoPOtoDO(form));
                        response = RedirectToAction("ViewAllPhotos", "Photo");
                    }
                    catch (Exception ex)
                    {
                        LogFile.DataFile(ex: ex);
                    }
                    finally
                    {
                    }
                }
                else
                {
                    response = View(form);
                }
            }
            else
            {
                TempData["Statement"] = "Please contact Admin to gain permissions to the page you are requesting.";
                response = RedirectToAction("Index", "Home");
            }
            return(response);
        }
예제 #2
0
        public ActionResult Upload(HttpPostedFileBase file, PhotoPO form)
        {
            ActionResult response = null;

            if (Session["RoleID"] != null && (byte)Session["RoleID"] == 3)
            {
                if (ModelState.IsValid)
                {
                    try
                    {
                        if (file.ContentLength > 0)
                        {
                            string fileName     = Path.GetFileName(file.FileName);
                            string path         = Path.Combine(Server.MapPath("~/Pictures"), fileName);
                            string relativePath = "/" + path.Replace(Server.MapPath("/"), "").Replace("\\", "/");
                            file.SaveAs(path);
                            form.Photo       = relativePath;
                            form.DateCreated = DateTime.Now;
                            _dataAccess.AddPhoto(PhotoMapper.PhotoPOtoDO(form));
                            response = RedirectToAction("ViewAllPhotos", "Photo");
                        }

                        else
                        {
                            response = View(form);
                        }
                    }
                    catch (Exception ex)
                    {
                        LogFile.DataFile(ex: ex);
                        throw ex;
                    }
                }
            }
            else
            {
                TempData["Statement"] = "Please contact Admin to gain permissions to the page you are requesting.";
                response = RedirectToAction("Index", "Home");
            }
            return(response);
        }