Esempio n. 1
0
        /// <summary>
        /// 删除单件衣物
        /// </summary>
        /// <param name="clothes">需要删除的衣物</param>
        /// <returns>删除结果 是否成功删除</returns>
        public static bool delete(Clothes clothes)
        {
            if (clothes == null)
            {
                return(false);
            }

            deleteClothesPic(clothes);

            return(SuitManager.deleteByClothes(clothes.id) & clothesDb.Delete(clothes));
        }
Esempio n. 2
0
        /// <summary>
        /// 获取指定编号的衣物
        /// </summary>
        /// <param name="clothesID">衣物ID</param>
        /// <returns>编号对应的衣物 未找到的返回null</returns>
        public static Clothes get(int clothesID)
        {
            Clothes clothes = clothesDb.GetById(clothesID);

            //确保衣物存在
            if (clothes == null)
            {
                return(null);
            }

            return(clothes);
        }
Esempio n. 3
0
        /// <summary>
        /// 获取指定编号的衣物信息
        /// </summary>
        /// <param name="clothesID">衣物ID</param>
        /// <returns>编号对应的衣物 未找到的返回null</returns>
        public static ClothesInfoResponse getInfo(int clothesID)
        {
            Clothes clothes = clothesDb.GetById(clothesID);

            //确保衣物存在
            if (clothes == null)
            {
                return(null);
            }

            return(new ClothesInfoResponse(clothes));
        }
Esempio n. 4
0
        /// <summary>
        /// 根据ID删除单件衣物
        /// </summary>
        /// <param name="clothesID">需要删除的衣物ID</param>
        /// <returns>删除结果 是否成功删除</returns>
        public static bool delete(int clothesID)
        {
            Clothes clothes = clothesDb.GetById(clothesID);

            if (clothes == null)
            {
                return(false);
            }

            deleteClothesPic(clothes);

            return(SuitManager.deleteByClothes(clothesID) & clothesDb.Delete(clothes));
        }
Esempio n. 5
0
        /// <summary>
        /// 保存衣物照片
        /// </summary>
        /// <param name="clothesPicFile">衣物照片</param>
        /// <param name="clothes">需要保存照片的衣物</param>
        /// <returns>保存结果 是否保存成功</returns>
        public static bool savePic(IFormFile clothesPicFile, Clothes clothes)
        {
            //确认衣物不为空
            if (clothes == null)
            {
                return(false);
            }

            //确认衣物照片不为空
            if (clothesPicFile != null)
            {
                string fileDir = Config.ClothesPicSaveDir;
                string tempDir = Config.TempDir;

                //确认保存路径存在
                if (!Directory.Exists(fileDir))
                {
                    Directory.CreateDirectory(fileDir);
                }
                if (!Directory.Exists(tempDir))
                {
                    Directory.CreateDirectory(tempDir);
                }

                string picPath  = clothes.picPath;
                string tempPath = clothes.tempPicPath;

                FileStream fs = System.IO.File.Create(tempPath);

                //保存照片
                clothesPicFile.CopyTo(fs);
                fs.Flush();
                fs.Close();

                //根据保存的照片获取衣物主题色
                double color = getPicMainColor(tempPath);
                clothes.color = color;
                clothesDb.Update(clothes);

                //图片压缩
                return(Utils.ImageUtil.compressImage(tempPath, picPath));
            }
            else
            {
                return(false);
            }
        }
Esempio n. 6
0
        /// <summary>
        /// 衣物更换衣橱
        /// </summary>
        /// <param name="clothesID">衣物ID</param>
        /// <param name="targetWardrobeID">需要切换至的衣橱ID</param>
        /// <returns>切换结果 是否成功切换衣橱</returns>
        public static bool changeWardrobe(int clothesID, int targetWardrobeID)
        {
            Clothes clothes = clothesDb.GetById(clothesID);

            //确保衣橱和衣物存在
            if (clothes == null || !WardrobeManager.exist(targetWardrobeID))
            {
                return(false);
            }

            //更换衣橱
            clothes.wardrobeID = targetWardrobeID;

            SuitManager.deleteByClothes(clothesID);

            return(clothesDb.Update(clothes));
        }
Esempio n. 7
0
        /// <summary>
        /// 删除衣物照片
        /// </summary>
        /// <param name="clothes">需要删除照片的衣物</param>
        /// <returns>删除结果 是否照片删除成功</returns>
        public static bool deleteClothesPic(Clothes clothes)
        {
            try
            {
                string filePath = clothes.picPath;

                if (File.Exists(filePath))
                {
                    File.Delete(filePath);
                }

                return(true);
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                return(false);
            }
        }
Esempio n. 8
0
        /// <summary>
        /// 穿着衣物
        /// </summary>
        /// <param name="clothesID">被穿着的衣物ID</param>
        /// <returns>操作结果 是否成功更新相关信息</returns>
        public static bool wear(int clothesID)
        {
            Clothes clothes = clothesDb.GetById(clothesID);

            //确认衣物存在
            if (clothes == null)
#if DEBUG
            { throw new Exception(); }
#else
            { return(false); }
#endif

            //更新衣橱被使用信息
            WardrobeManager.wear(clothes.wardrobeID);

            //更新衣物被穿着信息
            clothes.wear();

            return(clothesDb.Update(clothes));
        }