예제 #1
0
        public ActionResult ViewPhotoDetails(int photoID)
        {
            ActionResult response = null;
            PhotoDO      photo    = new PhotoDO();

            if (Session["RoleID"] != null)
            {
                try
                {
                    photo    = _dataAccess.ReadPhotoById(photoID);
                    response = View(PhotoMapper.PhotoDOtoPO(photo));
                }
                catch (Exception ex)
                {
                    LogFile.DataFile(ex: ex);
                }
                finally
                {
                }
            }
            else
            {
                TempData["Statement"] = "Please register to view this page.";
                response = RedirectToAction("Index", "Home");
            }
            return(response);
        }
예제 #2
0
        public ActionResult Upload(Guid Id, string message = null)
        {
            var ajaxMessage = new AjaxResponse {
                Success = true, Message = "上传成功!"
            };

            if (Id == null)
            {
                ajaxMessage.Success = false;
                ajaxMessage.Message = "产品不存在或已删除!";
                return(Json(ajaxMessage));
            }
            foreach (var fileKey in Request.Files.AllKeys)
            {
                var file = Request.Files[fileKey];
                try
                {
                    if (file != null)
                    {
                        var photoDO = new PhotoDO();
                        photoDO.Add(Id, "商品相册" + Path.GetExtension(file.FileName), file.InputStream);
                    }
                }
                catch (Exception ex)
                {
                    ajaxMessage.Success = false;
                    ajaxMessage.Message = ex.Message;
                }
            }
            return(Json(ajaxMessage));
        }
예제 #3
0
        public async Task <ActionResult> Create(
            [Bind(Include = "Id,Name,Log,Contact,Describe,Theme,CreateTime,UpdateTime,CreateBy,UpdateBy,TenantId")] Shop_Info shop_Info)
        {
            if (ModelState.IsValid)
            {
                shop_Info.Id = Guid.NewGuid();
                SetModelWithChangeStates(shop_Info, default(Guid?));

                //创建店铺相册
                var photoGallery = new Site_PhotoGallery();
                photoGallery.Id    = shop_Info.Id;
                photoGallery.Title = "【" + shop_Info.Name + "】-店铺相册";
                SetModelWithChangeStates(photoGallery, default(Guid?));
                db.Site_PhotoGallerys.Add(photoGallery);
                //上传店铺LOGO
                var file = Request.Files[0];
                if (file != null)
                {
                    var photoDO  = new PhotoDO();
                    var logoGuid = photoDO.Add(shop_Info.Id,
                                               "【" + shop_Info.Name + "】-店铺LOGO" + Path.GetExtension(file.FileName), file.InputStream);
                    shop_Info.Logo = logoGuid;
                }
                db.Shop_Infos.Add(shop_Info);
                await db.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }
            return(View(shop_Info));
        }
예제 #4
0
        public static PhotoPO PhotoDOtoPO(PhotoDO from)
        {
            PhotoPO to = new PhotoPO();

            to.PhotoID       = from.PhotoID;
            to.PhotoName     = from.PhotoName;
            to.Height        = from.Height;
            to.Width         = from.Width;
            to.ExtensionType = from.ExtensionType;
            to.Size          = from.Size;
            to.DateCreated   = from.DateCreated;
            to.Photo         = from.Photo;
            to.Byte          = from.Byte;
            to.AlbumID       = from.AlbumID;
            to.AlbumName     = from.AlbumName;
            return(to);
        }
        //method to view photos from database
        public List <PhotoDO> ViewAllPhotos()
        {
            List <PhotoDO> photoList       = new List <PhotoDO>();
            SqlConnection  connectionToSql = null;
            SqlCommand     storedProcedure = null;

            try
            {
                connectionToSql             = new SqlConnection(_connectionString);
                storedProcedure             = new SqlCommand("READ_ALL_PHOTOS", connectionToSql);
                storedProcedure.CommandType = System.Data.CommandType.StoredProcedure;
                connectionToSql.Open();
                SqlDataReader sqlDataReader = storedProcedure.ExecuteReader();

                while (sqlDataReader.Read())
                {
                    PhotoDO photo = new PhotoDO();
                    photoList.Add(photo);
                    photo.PhotoID       = Convert.ToInt32(sqlDataReader["PhotoID"]);
                    photo.PhotoName     = sqlDataReader["PhotoName"] as string;
                    photo.Height        = Convert.ToInt32(sqlDataReader["Height"]);
                    photo.Width         = Convert.ToInt32(sqlDataReader["Width"]);
                    photo.ExtensionType = sqlDataReader["ExtensionType"] as string;
                    photo.Size          = Convert.ToInt32(sqlDataReader["Size"]);
                    photo.DateCreated   = (DateTime)sqlDataReader["DateCreated"];
                    photo.Photo         = sqlDataReader["Photo"] as string;
                    photo.Byte          = sqlDataReader["Byte"] as byte?[];
                }
                sqlDataReader.Close();
            }
            catch (Exception ex)
            {
                LogFile.DataFile(ex: ex);
                throw ex;
            }
            finally
            {
                if (connectionToSql != null)
                {
                    connectionToSql.Close();
                    connectionToSql.Dispose();
                }
            }
            return(photoList);
        }
        //method to view only one row out of photo table in data base
        public PhotoDO ReadPhotoById(int photoID)
        {
            PhotoDO       photo           = new PhotoDO();
            SqlConnection connectionToSql = null;
            SqlCommand    storedProcedure = null;

            try
            {
                connectionToSql             = new SqlConnection(_connectionString);
                storedProcedure             = new SqlCommand("READ_PHOTO_BY_ID", connectionToSql);
                storedProcedure.CommandType = System.Data.CommandType.StoredProcedure;
                connectionToSql.Open();

                storedProcedure.Parameters.AddWithValue("@PhotoID", photoID);
                SqlDataReader reader = storedProcedure.ExecuteReader();
                reader.Read();
                photo.PhotoID       = (int)reader["PhotoID"];
                photo.PhotoName     = reader["PhotoName"] as string;
                photo.Height        = (int)reader["Height"];
                photo.Width         = (int)reader["Width"];
                photo.ExtensionType = reader["ExtensionType"] as string;
                photo.Size          = (int)reader["Size"];
                photo.DateCreated   = (DateTime)reader["DateCreated"];
                photo.Photo         = reader["Photo"] as string;
                photo.Byte          = reader["Byte"] as byte?[];

                reader.Close();
            }
            catch (Exception ex)
            {
                LogFile.DataFile(ex: ex);
                throw ex;
            }
            finally
            {
                if (connectionToSql != null)
                {
                    connectionToSql.Close();
                    connectionToSql.Dispose();
                }
            }
            return(photo);
        }
        //Method to upload photo to sql
        public void AddPhoto(PhotoDO photoDO)
        {
            SqlConnection connectionToSql = null;
            SqlCommand    storedProcedure = null;

            try
            {
                connectionToSql             = new SqlConnection(_connectionString);
                storedProcedure             = new SqlCommand("ADD_PHOTO", connectionToSql);
                storedProcedure.CommandType = System.Data.CommandType.StoredProcedure;
                connectionToSql.Open();

                storedProcedure.Parameters.AddWithValue("@PhotoName", photoDO.PhotoName);
                storedProcedure.Parameters.AddWithValue("@Height", photoDO.Height);
                storedProcedure.Parameters.AddWithValue("@Width", photoDO.Width);
                storedProcedure.Parameters.AddWithValue("@ExtensionType", photoDO.ExtensionType);
                storedProcedure.Parameters.AddWithValue("@Size", photoDO.Size);
                storedProcedure.Parameters.AddWithValue("@DateCreated", photoDO.DateCreated);
                storedProcedure.Parameters.AddWithValue("@Photo", photoDO.Photo);
                //stores relative path of photo to database
                storedProcedure.Parameters.AddWithValue("@Byte", photoDO.Byte);



                storedProcedure.ExecuteNonQuery();
            }
            catch (Exception ex)
            {
                LogFile.DataFile(ex: ex);
                throw ex;
            }
            finally
            {
                if (connectionToSql != null)
                {
                    connectionToSql.Close();
                    connectionToSql.Dispose();
                }
            }
        }
예제 #8
0
        public async Task <ActionResult> Edit(
            [Bind(Include = "Id,Name,Log,Contact,Describe,Theme,CreateTime,UpdateTime,CreateBy,UpdateBy,TenantId")] Shop_Info shop_Info)
        {
            if (ModelState.IsValid)
            {
                SetModelWithChangeStates(shop_Info, shop_Info.Id);
                //上传店铺LOGO
                var file = Request.Files[0];
                if (file != null)
                {
                    var photo = db.Site_Photos.FirstOrDefault(p => p.GalleryId == shop_Info.Id);
                    db.Site_Photos.Remove(photo);
                    var photoDO  = new PhotoDO();
                    var logoGuid = photoDO.Add(shop_Info.Id,
                                               "【" + shop_Info.Name + "】-店铺LOGO" + Path.GetExtension(file.FileName), file.InputStream);
                    shop_Info.Logo = logoGuid;
                }
                await db.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }
            return(View(shop_Info));
        }