Esempio n. 1
0
        /// <summary>
        /// تبديل تفضيل الاعلان
        /// </summary>
        /// <param name="ad"></param>
        /// <returns></returns>
        internal object AdFavoriteToggle(Ad ad)
        {
            if (ad == null)
            {
                return(new ResponseVM(RequestTypeEnumVM.Error, Token.AdNotFound));
            }

            var Favo = ad.AdFavorites.SingleOrDefault(c => c.FkUser_Id == AccessToken.UserId);

            //check is favorite
            if (Favo == null)
            {
                //favorite
                ad.AdFavorites.Add(new AdFavorite
                {
                    FkUser_Id = AccessToken.GetUserId(),
                });
            }
            else
            {
                //un favorite
                db.AdFavorites.Remove(Favo);
            }
            return(null);
        }
Esempio n. 2
0
        internal object Messages(MessageCreateVM message)
        {
            if (string.IsNullOrEmpty(message.Message))
            {
                return(new ResponseVM(RequestTypeEnumVM.Error, $"{Token.Message} : {Token.FiledIsRequired}"));
            }
            if (message.UserReciveId <= 0)
            {
                return(new ResponseVM(RequestTypeEnumVM.Error, $"{Token.UserRecivedId} : {Token.FiledIsRequired}"));
            }

            if (message.Message.Length > 500)
            {
                return(new ResponseVM(RequestTypeEnumVM.Error, $"{Token.Message} : {Token.MaxLength} = 500"));
            }

            if (!db.Users.Any(c => c.Id == message.UserReciveId))
            {
                return(new ResponseVM(RequestTypeEnumVM.Error, $"{Token.UserRecive} : {Token.NotFound} = 500"));
            }

            int UserLoggedId = AccessToken.GetUserId();

            var Chat = db.Chats.SingleOrDefault(c =>
                                                (c.FkUser_Id_Recived == UserLoggedId && c.FkUser_Id_Starting == message.UserReciveId)
                                                ||
                                                (c.FkUser_Id_Starting == UserLoggedId && c.FkUser_Id_Recived == message.UserReciveId)
                                                );

            var Message = new ChatMessage
            {
                Message   = message.Message,
                FkUser_Id = UserLoggedId,
                DateTime  = DateTime.Now
            };

            if (Chat == null)
            {
                //This Is New Chat
                db.Chats.Add(new Chat
                {
                    FkUser_Id_Starting = UserLoggedId,
                    FkUser_Id_Recived  = message.UserReciveId,
                    ChatMessages       = new
                                         List <ChatMessage>
                    {
                        Message
                    }
                });
            }
            else
            {
                //Save Message To Chat Messaging
                Chat.ChatMessages.Add(Message);
            }


            return(null);
        }
Esempio n. 3
0
 public static bool CheckIsBlocked()
 {
     using (TageerEntities db = new TageerEntities())
     {
         int UserId = AccessToken.GetUserId();
         return(db.Users.Find(UserId).IsBlocked);
     }
 }
Esempio n. 4
0
        internal object Comment(CommentVM commentVM, AdComment comment)
        {
            var Ad   = db.Ads.Find(commentVM.AdId);
            var User = db.Users.Find(AccessToken.GetUserId());

            if (Ad == null)
            {
                return(new ResponseVM(RequestTypeEnumVM.Error, Token.AdNotFound));
            }

            if (string.IsNullOrEmpty(commentVM.Comment))
            {
                return(new ResponseVM(RequestTypeEnumVM.Error, $"{Token.Comment} : {Token.FiledIsRequired}"));
            }

            if (commentVM.AdId <= 0)
            {
                return(new ResponseVM(RequestTypeEnumVM.Error, $"{Token.AdId} : {Token.FiledIsRequired}"));
            }

            if (commentVM.Comment.Length > 1000)
            {
                return(new ResponseVM(RequestTypeEnumVM.Error, $"{Token.Comment} : {Token.MaxLength} = 1000"));
            }

            comment.Comment   = commentVM.Comment;
            comment.FKAd_Id   = commentVM.AdId;
            comment.FkUser_Id = AccessToken.GetUserId();
            comment.DateTime  = DateTime.Now;

            db.AdComments.Add(comment);

            //Add Notifify To User Ownar Ad
            if (Ad.FkUser_Id != User.Id)
            {
                db.Notifications.Add(new Notification
                {
                    TitleAr              = $"علق {User.UserName} على اعلان {Ad.Title} ",
                    TitleEn              = $"{User.UserName} added comment to ad {Ad.Title}",
                    DataTime             = DateTime.Now,
                    UsersPrivateNotifies = new List <UsersPrivateNotify>
                    {
                        new UsersPrivateNotify
                        {
                            FkUser_Id = Ad.FkUser_Id
                        }
                    }
                });
            }
            return(null);
        }
Esempio n. 5
0
        internal object UpdateUserData(UserDataVM userDataVM)
        {
            var UserDataUpdate = db.Users.Find(AccessToken.GetUserId());

            //Check Is Update Language
            if (userDataVM.IsUpdateLanguage)
            {
                if (userDataVM.LangId <= 0)
                {
                    return(new ResponseVM(RequestTypeEnumVM.Error, $"{Token.Language} : {Token.FiledIsRequired}"));
                }

                if (!db.LanguageTypes.Any(c => c.Id == userDataVM.LangId))
                {
                    return(new ResponseVM(RequestTypeEnumVM.Error, $"{Token.Language} : {Token.NotFound}"));
                }

                UserDataUpdate.
                FKLanguage_Id = userDataVM.LangId;
            }

            //Check Is Update Email
            else if (userDataVM.IsUpdateEmail)
            {
                if (string.IsNullOrEmpty(userDataVM.Email))
                {
                    return(new ResponseVM(RequestTypeEnumVM.Error, $"{Token.Email} : {Token.FiledIsRequired}"));
                }

                if (!CheckedS.EmailIsCorrect(userDataVM.Email))
                {
                    return(new ResponseVM(RequestTypeEnumVM.Error, $"{Token.Email} : {Token.InvalidData}"));
                }

                if (db.Users.Where(c => c.Id != UserDataUpdate.Id).Any(c => c.Email == userDataVM.Email))
                {
                    return(new ResponseVM(RequestTypeEnumVM.Error, $"{Token.Email} : {Token.BeforeUsed}"));
                }

                UserDataUpdate.Email = userDataVM.Email;
                return(null);
            }

            //Check Is Update Phone
            else if (userDataVM.IsUpdatePhone)
            {
                if (string.IsNullOrEmpty(userDataVM.Phone))
                {
                    return new { RequestType = RequestTypeEnumVM.Error, Message = Token.Phone + " >> " + Token.FiledIsRequired }
                }
                ;

                if (!CheckedS.NumberValid(userDataVM.Phone))
                {
                    return new { RequestType = RequestTypeEnumVM.Error, Message = Token.Phone + " >> " + Token.InvalidNumber }
                }
                ;



                if (userDataVM.Phone.Length > 15)
                {
                    return new { RequestType = RequestTypeEnumVM.Error, Message = Token.Phone + " >> " + Token.MaxLength + "= 15" }
                }
                ;


                UserDataUpdate.PhoneNumber = userDataVM.Phone;
            }
            //Check Is Update Password
            else if (userDataVM.IsUpdatePassword)
            {
                if (string.IsNullOrEmpty(userDataVM.Password))
                {
                    return new { RequestType = RequestTypeEnumVM.Error, Message = Token.Password + " >> " + Token.FiledIsRequired }
                }
                ;
                UserDataUpdate.Password = userDataVM.Password;
            }
            //Check Is Update UserName
            else if (userDataVM.IsUpdateUserName)
            {
                if (string.IsNullOrEmpty(userDataVM.UserName))
                {
                    return new { RequestType = RequestTypeEnumVM.Error, Message = Token.Password + " >> " + Token.FiledIsRequired }
                }
                ;

                if (db.Users.Where(c => c.Id != UserDataUpdate.Id).Any(c => c.UserName == userDataVM.UserName))
                {
                    return new { RequestType = RequestTypeEnumVM.Error, Message = Token.UserName + " >> " + Token.ErrorDuplicate }
                }
                ;

                UserDataUpdate.UserName = userDataVM.UserName;
            }
            //Check Is Update Full Name
            else if (userDataVM.IsUpdateFullName)
            {
                if (string.IsNullOrEmpty(userDataVM.FullName))
                {
                    return new { RequestType = RequestTypeEnumVM.Error, Message = Token.FullName + " >> " + Token.FiledIsRequired }
                }
                ;

                UserDataUpdate.FullName = userDataVM.FullName;
            }

            //Check Is Update Country
            else if (userDataVM.IsUpdateCountry)
            {
                if (userDataVM.CountryId <= 0)
                {
                    return new { RequestType = RequestTypeEnumVM.Error, Message = Token.Country + " >> " + Token.FiledIsRequired }
                }
                ;

                UserDataUpdate.Address.FKCountry_Id = userDataVM.CountryId;
            }
            //Check Is Update City
            else if (userDataVM.IsUpdateCity)
            {
                if (string.IsNullOrEmpty(userDataVM.City))
                {
                    return new { RequestType = RequestTypeEnumVM.Error, Message = Token.City + " >> " + Token.FiledIsRequired }
                }
                ;

                UserDataUpdate.Address.City = userDataVM.City;
            }
            //Check Is Update Province
            else if (userDataVM.IsUpdateProvince)
            {
                if (userDataVM.ProvinceId <= 0)
                {
                    return new { RequestType = RequestTypeEnumVM.Error, Message = Token.Province + " >> " + Token.FiledIsRequired }
                }
                ;

                UserDataUpdate.Address.FkProvince_Id = userDataVM.ProvinceId;
            }
            //Check Is Update Profile Image
            else if (userDataVM.IsUpdateImageProfile)
            {
                if (string.IsNullOrEmpty(userDataVM.FileBase64))
                {
                    return new { RequestType = RequestTypeEnumVM.Error, Message = Token.ImageProfile + " >> " + Token.FiledIsRequired }
                }
                ;

                //Uplaod Image
                FileSaveVM FileSave = FileService.SaveFileBase64(new FileSaveVM()
                {
                    FileBase64     = userDataVM.FileBase64,
                    ServerPathSave = "/Files/Images/Users/Profile/"
                });


                if (!FileSave.IsSave)
                {
                    return new { RequestType = RequestTypeEnumVM.Error, Message = Token.CanNotSaveFile }
                }
                ;

                UserDataUpdate.AllFile.FileUrl             = FileSave.SavedPath;
                UserDataUpdate.AllFile.FKAppInformation_Id = AppInformationEnumVM.ApiLink
                ;
            }

            return(null);
        }
Esempio n. 6
0
        /// <summary>
        /// Cereate New Ad
        /// </summary>
        /// <param name="adCereateVM"></param>
        /// <param name="pagesAllow"></param>
        /// <returns></returns>
        internal object Ad(AdCreateVM adCereateVM)
        {
            //Check Requierd
            if (string.IsNullOrEmpty(adCereateVM.Title))
            {
                return(ResponseVM.FieldIsRequierd(Token.Title));
            }
            if (string.IsNullOrEmpty(adCereateVM.Description))
            {
                return(ResponseVM.FieldIsRequierd(Token.Description));
            }
            if (adCereateVM.Price <= 0)
            {
                return(ResponseVM.FieldIsRequierd(Token.Price));
            }
            if (adCereateVM.CategoryId <= 0)
            {
                return(ResponseVM.FieldIsRequierd(Token.Category));
            }
            if (adCereateVM.SubCategoryId <= 0)
            {
                return(ResponseVM.FieldIsRequierd(Token.SubCategory));
            }
            if (adCereateVM.Images.Count <= 0)
            {
                return(ResponseVM.FieldIsRequierd(Token.Images));
            }

            Ad Ad = new Ad();


            //Add Ad Individual Field
            AdsService.ImportAdIndividualField(Ad, adCereateVM.AdIndividualField);
            //Add Ad Groups Field
            AdsService.ImportAdGroupsField(Ad, adCereateVM.AdGroupsField);
            //Add Ad Direct Field
            AdsService.ImportAdDirectField(Ad, adCereateVM.AdDirectField);



            //Save Images
            Album Album = new Album();

            foreach (var img in adCereateVM.Images)
            {
                FileSaveVM FileSave = FileService.SaveFileBase64(new FileSaveVM()
                {
                    FileBase64     = img.FileBase64,
                    ServerPathSave = "/Files/Images/"
                });

                if (!FileSave.IsSave)
                {
                    return(new ResponseVM(RequestTypeEnumVM.Error, $"{Token.CanNotSaveFile} {img.FileName}"));
                }

                Album.AlbumFiles.Add(new AlbumFile
                {
                    AllFile = new AllFile
                    {
                        FkFileType_Id       = FileTypeEnumVM.Image,
                        FileUrl             = FileSave.SavedPath,
                        FKAppInformation_Id = AppInformationEnumVM.ApiFiles
                    }
                });
            }
            Ad.Album = Album;



            Ad.CreateDateTime       = DateTime.Now;
            Ad.Title                = adCereateVM.Title;
            Ad.Description          = adCereateVM.Description;
            Ad.Price                = adCereateVM.Price;
            Ad.FkCategory_Id        = adCereateVM.CategoryId;
            Ad.FkSubCategory_Id     = adCereateVM.SubCategoryId;
            Ad.FkRentalTimesType_Id = adCereateVM.RentalTimeTypeId;
            Ad.FkUser_Id            = AccessToken.GetUserId();
            db.Ads.Add(Ad);
            return(null);
        }