Example #1
0
        // PUT api/Temp/5
        public async Task<IHttpActionResult> PutAd(int id, Ad ad)
        {
            if (!ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }

            if (id != ad.Id)
            {
                return BadRequest();
            }

            db.Entry(ad).State = EntityState.Modified;

            try
            {
                await db.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!AdExists(id))
                {
                    return NotFound();
                }
                else
                {
                    throw;
                }
            }

            return StatusCode(HttpStatusCode.NoContent);
        }
 public ActionResult CreateMobileAccessoriesAd()
 {
     if (Request.IsAuthenticated)
     {
         Ad ad = new Ad();
         return View(ad);
     }
     return RedirectToAction("Register", "Account");
 }
Example #3
0
 // GET: /Jobs/Create
 public ActionResult Create()
 {
     if (Request.IsAuthenticated)
     {
         Ad ad = new Ad();
         return View(ad);
     }
     return RedirectToAction("Index", "Home");
 }
Example #4
0
        public async Task<IHttpActionResult> PostAd(Ad ad)
        {
            if (!ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }

            db.Ads.Add(ad);
            await db.SaveChangesAsync();

            return CreatedAtRoute("DefaultApi", new { id = ad.Id }, ad);
        }
Example #5
0
 public ActionResult Create(string category, string subcategory = null)
 {
     if (Request.IsAuthenticated)
     {
         if (checkCategory(category, subcategory))
         {
             ViewBag.category = category;
             ViewBag.subcategory = subcategory;
             Ad ad = new Ad();
             return View(ad);
         }
         return HttpNotFound();
     }
     return RedirectToAction("Register", "Account");
 }
 public void MyAdLocation(string city, string popularPlace, string exectLocation,ref Ad ad,string SaveOrUpdate)
 {
     AdsLocation loc = new AdsLocation();
     if (city != null)
     {
         var citydb = db.Cities.FirstOrDefault(x => x.cityName.Equals(city, StringComparison.OrdinalIgnoreCase));
         if (citydb == null)
         {
             City cit = new City();
             cit.cityName = city;
             cit.addedBy = System.Web.HttpContext.Current.User.Identity.GetUserId();
             cit.addedBy = System.Web.HttpContext.Current.User.Identity.GetUserId();
             cit.addedOn = DateTime.UtcNow;
             db.Cities.Add(cit);
             db.SaveChanges();
             loc.cityId = cit.Id;
             if (popularPlace != null)
             {
                 popularPlace pop = new popularPlace();
                 pop.cityId = cit.Id;
                 pop.name = popularPlace;
                 pop.addedBy = System.Web.HttpContext.Current.User.Identity.GetUserId();
                 pop.addedOn = DateTime.UtcNow;
                 db.popularPlaces.Add(pop);
                 db.SaveChanges();
                 loc.popularPlaceId = pop.Id;
             }
         }
         else
         {
             loc.cityId = citydb.Id;
             if (popularPlace != null)
             {
                 var ppp = db.popularPlaces.FirstOrDefault(x => x.City.cityName.Equals(city, StringComparison.OrdinalIgnoreCase) && x.name.Equals(popularPlace, StringComparison.OrdinalIgnoreCase));
                 if (ppp == null)
                 {
                     popularPlace pop = new popularPlace();
                     pop.cityId = citydb.Id;
                     pop.name = popularPlace;
                     pop.addedBy = System.Web.HttpContext.Current.User.Identity.GetUserId();
                     pop.addedOn = DateTime.UtcNow;
                     db.popularPlaces.Add(pop);
                     db.SaveChanges();
                     loc.popularPlaceId = pop.Id;
                 }
                 else
                 {
                     loc.popularPlaceId = ppp.Id;
                 }
             }
         }
         loc.exectLocation = exectLocation;
         loc.Id = ad.Id;
         if (SaveOrUpdate == "Save")
         {
             ad.AdsLocation = loc;
            // db.AdsLocations.Add(loc);
         }
         else if (SaveOrUpdate == "Update")
         {
             db.Entry(loc).State = EntityState.Modified;
         }
             db.SaveChanges();
         
     }
 }
        public void MyAd(ref Ad ad,string SaveOrUpdate,string cateogry = null,string subcategory = null)
        {
            ad.status = "a";
            var type = System.Web.HttpContext.Current.Request["type"];
            var isbiding = System.Web.HttpContext.Current.Request["bidingAllowed"];
            var condition = System.Web.HttpContext.Current.Request["condition"];
            var pp = System.Web.HttpContext.Current.Request["price"];
            string[] prices = pp.Split(',');   //exception: object reference not set to instance of object
            if (type == "sell")
            {
                ad.type = true;
            }
            else
            {
                ad.type = false;
            }
            if (isbiding == "fixedPrice")
            {
                pp = prices[0];
                var nn = System.Web.HttpContext.Current.Request["isNegotiable"];
                if (nn == "on")
                {
                    ad.isnegotiable = "y";
                }
                else
                {
                    ad.isnegotiable = "n";
                }
            }
            else if (isbiding == "allowBiding")
            {
                pp = prices[1];
                ad.isnegotiable = "b";
            }

            if (condition == "new")
            {
                ad.condition = "n";
            }
            else if (condition == "unboxed")
            {
                ad.condition = "b";
            }
            else
            {
                ad.condition = "u";
            }
            if (pp != null && pp != "")
            {
                ad.price = int.Parse(pp);
            }
            ad.description = System.Web.HttpUtility.HtmlEncode(ad.description);
            ad.postedBy = System.Web.HttpContext.Current.User.Identity.GetUserId();
            if (SaveOrUpdate == "Save")
            {
                ad.category = cateogry;
                ad.subcategory = subcategory;
                ad.time = DateTime.UtcNow;
            }
            else if (SaveOrUpdate == "Update")
            {
                ad.time =DateTime.Parse(System.Web.HttpContext.Current.Request["time"]);
                if (ad.category == null)
                {
                    ad.category = System.Web.HttpContext.Current.Request["category"];
                }
                if (ad.subcategory == null)
                {
                    ad.subcategory = System.Web.HttpContext.Current.Request["subcategory"];
                }
                

            }
        }
        public int SaveLaptopBrandModel(Ad ad)
        {
            ad.status = "a";
            var company = Request["brand"];
            var model = Request["model"];
            if (company != null && company != "")
            {
                company = company.Trim();
                model = model.Trim();
            }
            if (true) //company != null
            {

                var allBrands = (db.LaptopBrands.Select(x => x.brand)).AsEnumerable(); //getBrands
                bool isNewBrand = true;
                foreach (var brand in allBrands)
                {
                    if (brand == company)
                    {
                        isNewBrand = false;
                    }
                }
                if (isNewBrand)
                {
                    LaptopBrand mob = new LaptopBrand();
                    mob.brand = company;
                    mob.addedBy = System.Web.HttpContext.Current.User.Identity.GetUserId();
                    mob.time = DateTime.UtcNow;
                    if (company == null || company == "")
                    {
                        mob.status = "a";
                    }
                    else
                    {
                        mob.status = "p";
                    }
                    db.LaptopBrands.Add(mob);
                    db.SaveChanges();

                    LaptopModel mod = new LaptopModel();
                    mod.model = model;
                    mod.brandId = mob.Id;
                    mod.time = DateTime.UtcNow;
                    if (model == null || model == "")
                    {
                        mod.status = "a";
                    }
                    else
                    {
                        mod.status = "p";
                    }
                    mod.addedBy = System.Web.HttpContext.Current.User.Identity.GetUserId();
                    db.LaptopModels.Add(mod);
                    db.SaveChanges();
                    ad.status = "p";
                }
                else
                {
                    var allModels = db.LaptopModels.Where(x => x.LaptopBrand.brand == company).Select(x => x.model);
                    bool isNewModel = true;
                    foreach (var myModel in allModels)
                    {
                        if (myModel == model)
                        {
                            isNewModel = false;
                        }
                    }
                    if (isNewModel)
                    {
                        ad.status = "p";
                        var brandId = db.LaptopBrands.FirstOrDefault(x => x.brand.Equals(company));
                        LaptopModel mod = new LaptopModel();
                        mod.brandId = brandId.Id;
                        mod.model = model;
                        if (model == null || model == "")
                        {
                            mod.status = "a";
                        }
                        else
                        {
                            mod.status = "p";
                        }
                        mod.addedBy = System.Web.HttpContext.Current.User.Identity.GetUserId();
                        mod.time = DateTime.UtcNow;
                        db.LaptopModels.Add(mod);
                        try
                        {
                            db.SaveChanges();
                        }
                        catch (Exception e)
                        {
                            string s = e.ToString();
                        }
                    }
                }
                var laptopModel = db.LaptopModels.FirstOrDefault(x => x.LaptopBrand.brand == company && x.model == model);
                return laptopModel.Id;
            }
        }
        public void ReplaceAdImages(ref Ad ad, FileName[] filenames)
        {
            string newFileName = "";
            int count = 1;
            var id = ad.Id;
            var imaa = db.AdImages.Where(x => x.adId.Equals(id)).Count();
            count = imaa + 1;
            for (int i = 1; i < filenames.Length; i++)
            {
                 IAmazonS3 client;
                 try
                 {
                     using (client = new AmazonS3Client(Amazon.RegionEndpoint.USEast1))
                     {
                         GetObjectRequest request = new GetObjectRequest
                         {
                             BucketName = _bucketName,
                             Key = _folderName + filenames[i].fileName
                         };
                         using (GetObjectResponse response = client.GetObject(request))
                         {
                             string filename = filenames[i].fileName;
                             if (!System.IO.File.Exists(filename))
                             {
                                 string extension = System.IO.Path.GetExtension(filenames[i].fileName);
                                 newFileName = ad.Id.ToString() + "_" + count + extension;

                                 client = new AmazonS3Client(Amazon.RegionEndpoint.USEast1);

                                 CopyObjectRequest request1 = new CopyObjectRequest()
                                 {
                                     SourceBucket = _bucketName,
                                     SourceKey = _folderName + filename,
                                     DestinationBucket = _bucketName,
                                     CannedACL = S3CannedACL.PublicRead,//PERMISSION TO FILE PUBLIC ACCESIBLE
                                     DestinationKey = _folderName + newFileName
                                 };
                                 CopyObjectResponse response1 = client.CopyObject(request1);

                                 AdImage image = new AdImage();
                                 image.imageExtension = extension;
                                 image.adId = ad.Id;
                                 db.AdImages.Add(image);
                                 db.SaveChanges();
                                 count++;



                                 DeleteObjectRequest deleteObjectRequest =
                                 new DeleteObjectRequest
                                 {
                                     BucketName = _bucketName,
                                     Key = _folderName + filenames[i].fileName
                                 };
                                 AmazonS3Config config = new AmazonS3Config();
                                 config.ServiceURL = "https://s3.amazonaws.com/";
                                 using (client = Amazon.AWSClientFactory.CreateAmazonS3Client(
                                      _awsAccessKey, _awsSecretKey, config))
                                 {
                                     client.DeleteObject(deleteObjectRequest);
                                 }
                             }
                         }
                     }
                 }
                 catch (Exception e)
                 {

                 }
            }
        }
        public void SaveTags(string s,ref Ad ad,string addOrUpdate = "add")
        {
            if(addOrUpdate == "update")
            {
                var adid = ad.Id;
                var adtags = db.AdTags.Where(x => x.adId.Equals(adid)).ToList();
                foreach (var cc in adtags)
                {
                    db.AdTags.Remove(cc);
                }
                 db.SaveChanges();
            }
            string[] values = s.Split(',');
            Inspinia_MVC5_SeedProject.Models.Tag[] tags = new Inspinia_MVC5_SeedProject.Models.Tag[values.Length];
            AdTag[] qt = new AdTag[values.Length];
            for (int i = 0; i < values.Length; i++)
            {
                values[i] = values[i].Trim();
                string ss = values[i];
                if (ss != "")
                {
                    var data = db.Tags.FirstOrDefault(x => x.name.Equals(ss, StringComparison.OrdinalIgnoreCase));

                    tags[i] = new Inspinia_MVC5_SeedProject.Models.Tag();
                    if (data != null)
                    {
                        tags[i].Id = data.Id;
                    }
                    else
                    {
                        tags[i].name = values[i];
                        tags[i].time = DateTime.UtcNow;
                        tags[i].createdBy = System.Web.HttpContext.Current.User.Identity.GetUserId();
                        db.Tags.Add(tags[i]);
                    }
                }
                else
                {
                    tags[i] = null;
                }
            }
            try
            {
                db.SaveChanges();
            }
            catch (Exception e)
            {
                string sb = e.ToString();
            }
            for (int i = 0; i < values.Length; i++)
            {
                if (tags[i] != null)
                {
                    qt[i] = new AdTag();
                    qt[i].adId = ad.Id;
                    qt[i].tagId = tags[i].Id;
                    db.AdTags.Add(qt[i]);
                }
            }
            try
            {
                db.SaveChanges();
            }
            catch (Exception e)
            {
                string sb = e.ToString();
            }
        }
 // GET: /RealEstate/Create
 public ActionResult Create()
 {
     Ad ad = new Ad();
     return View(ad);
 }
Example #12
0
        public async Task<object> SaveSkills(string s,Ad ad, bool update = false)
        {
            if (update)
            {
                var adid = ad.Id;
                var adtags = db.JobSkills.Where(x => x.adId.Equals(adid)).ToList();
                foreach (var cc in adtags)
                {
                    db.JobSkills.Remove(cc);
                }
                await db.SaveChangesAsync();
            }
            if(s == "" || s == null)
            {
                return true;
            }
            string[] values = s.Split(',');
            Skill[] tags = new Skill[values.Length];
            JobSkill[] qt = new JobSkill[values.Length];
            for (int i = 0; i < values.Length; i++)
            {
                values[i] = values[i].Trim();
                string ss = values[i];
                if (ss != "")
                {
                    var data = db.Skills.FirstOrDefault(x => x.name.Equals(ss, StringComparison.OrdinalIgnoreCase));

                    tags[i] = new Skill();
                    if (data != null)
                    {
                        tags[i].Id = data.Id;
                    }
                    else
                    {
                        tags[i].name = values[i];
                        tags[i].time = DateTime.UtcNow;
                        tags[i].addedBy = System.Web.HttpContext.Current.User.Identity.GetUserId();
                        db.Skills.Add(tags[i]);
                    }
                }
                else
                {
                    tags[i] = null;
                }
            }
            try
            {
                db.SaveChanges();
            }
            catch (Exception e)
            {
                string sb = e.ToString();
            }
            for (int i = 0; i < values.Length; i++)
            {
                if (tags[i] != null)
                {
                    qt[i] = new JobSkill();
                    qt[i].adId = ad.Id;
                    qt[i].tagId = tags[i].Id;
                    db.JobSkills.Add(qt[i]);
                }
            }
            try
            {
                db.SaveChanges();
            }
            catch (Exception e)
            {
                string sb = e.ToString();
            }
            return true;
        }
Example #13
0
        public async Task<bool> SaveAd(Ad ad,bool update = false)
        {
            JobAd jobAd = new JobAd();
            if(update){
              //  jobAd =await db.JobAds.FindAsync(ad.Id);
                jobAd.adId = ad.Id;
            }
            //else{
            //    jobAd = new JobAd();
            //}
             
            ad.status = "a";
            ad.category = "Jobs";
            var seats = System.Web.HttpContext.Current.Request["seats"];
            if ( seats != null && seats != "")
            {
                jobAd.seats = int.Parse(seats);
            } 
            jobAd.qualification = System.Web.HttpContext.Current.Request["qualification"];
            jobAd.exprience = System.Web.HttpContext.Current.Request["exprience"];
            if(System.Web.HttpContext.Current.Request["salary"] != null && System.Web.HttpContext.Current.Request["salary"] != "")
            {
                ad.price = int.Parse(System.Web.HttpContext.Current.Request["salary"]);
            }
            ad.isnegotiable = System.Web.HttpContext.Current.Request["gender"];
            var skills = System.Web.HttpContext.Current.Request["skills"];
            jobAd.careerLevel = System.Web.HttpContext.Current.Request["careerLevel"];
            var lastDateToApply = System.Web.HttpContext.Current.Request["lastDateToApply"];
            if (lastDateToApply != null && lastDateToApply != "") 
            {
                jobAd.lastDateToApply = DateTime.Parse(lastDateToApply);
            }
            ad.condition = System.Web.HttpContext.Current.Request["shift"];
            jobAd.salaryType = System.Web.HttpContext.Current.Request["salaryType"];
            

            ad.description = System.Web.HttpUtility.HtmlEncode(ad.description);
            ad.postedBy = System.Web.HttpContext.Current.User.Identity.GetUserId();



            if (!update)
            {
                jobAd.category1 = System.Web.HttpContext.Current.Request["category"];
                ad.subcategory = System.Web.HttpContext.Current.Request["subcategory"];
                ad.time = DateTime.UtcNow;

                db.Ads.Add(ad);
                await db.SaveChangesAsync();
                jobAd.adId = ad.Id;
                db.JobAds.Add(jobAd);
                await db.SaveChangesAsync();
            }
            else if (update)
            {
                ad.time = DateTime.Parse(System.Web.HttpContext.Current.Request["time"]);
                jobAd.category1 = System.Web.HttpContext.Current.Request["category"];
                ad.subcategory = System.Web.HttpContext.Current.Request["subcategory"];
                db.Entry(ad).State = EntityState.Modified;
                await db.SaveChangesAsync();
                db.Entry(jobAd).State = EntityState.Modified;
                await db.SaveChangesAsync();
            }
            

            

            return true;
        }
 // GET: /Electronics/Create
 public ActionResult Create()
 {
     ViewBag.postedBy = new SelectList(db.AspNetUsers, "Id", "Email");
     Ad ad = new Ad();
     return View(ad);
 }
        public async Task<bool> saveBikeAd(Ad ad, bool update = false)
        {
            //  ad.category = "Vehicles";
            //  ad.subcategory = "Cars";
            BikeAd mobileAd = new  BikeAd();
            if (Request["year"] != "" && Request["year"] != null)
            {
                mobileAd.year = short.Parse(Request["year"]);
            }
            if (Request["kmDriven"] != null && Request["kmDriven"] != "")
            {
                mobileAd.kmDriven = int.Parse(Request["kmDriven"]);
            }
            mobileAd.adId = ad.Id;
            if (Request["noOfOwners"] != null && Request["noOfOwners"] != "")
            {
                mobileAd.noOfOwners = short.Parse(Request["noOfOwners"]);
            }
            if (Request["registeredCity"] != null && Request["registeredCity"] != "")
            {
                var city = Request["registeredCity"];

                mobileAd.registeredCity = await SaveCity(city);
            }
            mobileAd.bikeModel = SaveBikesBrandModel(ref ad);

            if (update)
            {
                db.Entry(mobileAd).State = EntityState.Modified;
            }
            else
            {
                db.BikeAds.Add(mobileAd);
            }
            try
            {
                await db.SaveChangesAsync();
            }
            catch (DbEntityValidationException e)
            {
                string s = e.ToString();
                List<string> errorMessages = new List<string>();
                foreach (DbEntityValidationResult validationResult in e.EntityValidationErrors)
                {
                    string entityName = validationResult.Entry.Entity.GetType().Name;
                    foreach (DbValidationError error in validationResult.ValidationErrors)
                    {
                        errorMessages.Add(entityName + "." + error.PropertyName + ": " + error.ErrorMessage);
                    }
                }
            }
            return true;
        }