public void editRoomType(RoomTypeVM roomTypeVM)
        {
            RoomType roomType = new RoomType();

            _iMapper.Map(roomTypeVM, roomType);
            List <int> img_del = new List <int>();

            foreach (KeyValuePair <int, string> kvp in roomTypeVM.MapImgUrl)
            {
                if (kvp.Value == "")
                {
                    img_del.Add(kvp.Key);
                }
                else
                {
                    ImgStorage imgStorage = new ImgStorage();
                    if (kvp.Key > 0)
                    {
                        imgStorage.IdImgsto = kvp.Key;
                    }

                    imgStorage.ImgstoIdrootyp = roomTypeVM.IdRoomtype;
                    imgStorage.ImgstoUrl      = kvp.Value;
                    roomType.ImgStorages.Add(imgStorage);
                }
            }
            foreach (int val in img_del)
            {
                _iImgStorageDAL.delete(val);
            }
            _iRoomTypeDAL.updateRoomtype(roomType);
        }
예제 #2
0
        public void EditRoomType(RoomTypeVM roomTypeVM, List <int> listdel)
        {
            RoomType roomType = new RoomType();

            mapper.Map(roomTypeVM, roomType);
            List <ImgStorage> listadd = new List <ImgStorage>();

            foreach (ImageVM imageVM in roomTypeVM.ListImg)
            {
                ImgStorage imgStorage = new ImgStorage();
                mapper.Map(imageVM, imgStorage);
                imgStorage.ImgstoIdrootyp = roomType.IdRoomtype;
                if (imageVM.IdImgsto == 0)
                {
                    listadd.Add(imgStorage);
                }
            }

            try
            {
                if (listdel != null)
                {
                    _roomTypeDALManageFacade.DeleteImage(listdel);
                }
                _roomTypeDALManageFacade.UpdateRoomtype(roomType);
                _roomTypeDALManageFacade.AddImage(listadd);
            }
            catch (Exception e)
            {
            }
        }
예제 #3
0
        public void AddRoomType(RoomTypeVM roomTypeVM)
        {
            int               idRoomType = _roomTypeDALManageFacade.GetnextidRoomType();
            RoomType          roomType   = new RoomType();
            List <ImgStorage> imgstolist = new List <ImgStorage>();

            mapper.Map(roomTypeVM, roomType);
            roomType.RoTyActiveflag = true;
            foreach (ImageVM imageVM in roomTypeVM.ListImg)
            {
                ImgStorage imgStorage = new ImgStorage();
                mapper.Map(imageVM, imgStorage);
                imgStorage.ImgstoIdrootyp = idRoomType;
                imgstolist.Add(imgStorage);
            }
            roomType.ImgStorages = imgstolist;
            try
            {
                _roomTypeDALManageFacade.AddRoomtype(roomType);
                _roomTypeDALManageFacade.AddImage(imgstolist);
            }
            catch (Exception e)
            {
            }
        }
        public void delete(int id)
        {
            ImgStorage imgStorage = _appDbContext.ImgStorages.Find(id);

            _appDbContext.ImgStorages.Remove(imgStorage);
            _appDbContext.SaveChanges();
        }
예제 #5
0
        public void UpdateUser(UserVM userVM, List <int> listdel, bool isPassChanged)
        {
            User user = new User();

            mapper.Map(userVM, user);
            if (isPassChanged)
            {
                user.UserPassword = Md5.CreateMD5Hash(user.UserPassword);
            }
            List <UserRole>   ListRole = new List <UserRole>();
            List <ImgStorage> ListImg  = new List <ImgStorage>();

            foreach (RoleVM roleVM in userVM.ListRole)
            {
                UserRole userRole = new UserRole
                {
                    UserolIduser = user.IdUser,
                    UserolIdrole = roleVM.IdRole
                };
                ListRole.Add(userRole);
            }
            foreach (ImageVM imageVM in userVM.ListImg)
            {
                ImgStorage imgStorage = new ImgStorage();
                mapper.Map(imageVM, imgStorage);
                imgStorage.ImgstoIduser = user.IdUser;
                if (imageVM.IdImgsto == 0)
                {
                    ListImg.Add(imgStorage);
                }
            }
            try
            {
                _userDALManageFacade.DelUserRole(user.IdUser);
                _userDALManageFacade.AddUserRole(ListRole);
                if (listdel != null)
                {
                    _userDALManageFacade.DeleteImage(listdel);
                }
                _userDALManageFacade.UpdateUser(user);
                if (ListImg != null)
                {
                    _userDALManageFacade.AddImage(ListImg);
                }
            }
            catch (Exception)
            {
                throw;
            }
        }
        public void addRoomType(RoomTypeVM roomTypeVM)
        {
            int               idRoomType = _iRoomTypeDAL.getnextid();
            RoomType          roomType   = new RoomType();
            List <ImgStorage> imgstolist = new List <ImgStorage>();

            _iMapper.Map(roomTypeVM, roomType);
            foreach (string imgurl in roomTypeVM.ListImgURL)
            {
                ImgStorage imgStorage = new ImgStorage();
                imgStorage.ImgstoUrl      = imgurl;
                imgStorage.ImgstoIdrootyp = idRoomType;
                imgstolist.Add(imgStorage);
            }
            roomType.ImgStorages = imgstolist;
            _iRoomTypeDAL.addRoomtype(roomType);
        }
        public void Delete(List <int> listdel)
        {
            List <ImgStorage> list = new List <ImgStorage>();

            foreach (int id in listdel)
            {
                ImgStorage imgStorage = AppDbContext.Instance.ImgStorages.Where(x => x.IdImgsto == id).SingleOrDefault();
                AppDbContext.Instance.Entry(imgStorage).State = EntityState.Detached;
                if (imgStorage != null)
                {
                    list.Add(imgStorage);
                }
            }

            AppDbContext.Instance.ImgStorages.RemoveRange(list);
            AppDbContext.Instance.SaveChanges();
        }
예제 #8
0
        public void AddUser(UserVM userVM)
        {
            int               idUser   = _userDALManageFacade.GetnextUserid();
            User              user     = new User();
            List <UserRole>   ListRole = new List <UserRole>();
            List <ImgStorage> ListImg  = new List <ImgStorage>();

            mapper.Map(userVM, user);
            user.UserPassword = Md5.CreateMD5Hash(user.UserPassword);
            foreach (RoleVM roleVM in userVM.ListRole)
            {
                UserRole userRole = new UserRole
                {
                    UserolIduser = idUser,
                    UserolIdrole = roleVM.IdRole
                };
                ListRole.Add(userRole);
            }
            foreach (ImageVM imgVM in userVM.ListImg)
            {
                ImgStorage imgStorage = new ImgStorage
                {
                    ImgstoIduser = idUser,
                    ImgstoUrl    = imgVM.ImgstoUrl
                };
                ListImg.Add(imgStorage);
            }
            try
            {
                _userDALManageFacade.AddUser(user);
                _userDALManageFacade.AddUserRole(ListRole);
                _userDALManageFacade.AddImage(ListImg);
            }
            catch (Exception)
            {
                throw;
            }
        }