Пример #1
0
        public object Create(AdCreateVM adCereateVM)
        {
            try
            {
                object ObjectReturn = CreateS.Ad(adCereateVM);
                if (ObjectReturn != null)
                {
                    return(ObjectReturn);
                }

                db.SaveChanges();
                return(new ResponseVM(RequestTypeEnumVM.Success, Token.Created));
            }
            catch (Exception ex)
            {
                return(new ResponseVM(RequestTypeEnumVM.Error, Token.SomeErrorInServer, ex));
            }
        }
Пример #2
0
 public IHttpActionResult CreateAd(AdCreateVM adCereateVM)
 {
     return(Json(AdsData.Create(adCereateVM)));
 }
Пример #3
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);
        }