Пример #1
0
        // save Maker info For Company
        private void AddOrUpdateMakerInfoForCompany(AutoMaxContext database, Models.DataModel.MakeMappingViewModel viewModel)
        {
            MakerMapping mm = database.MakerMapping.FirstOrDefault(x => x.MakerId == viewModel.ID);

            if (mm == default(MakerMapping))
            {
                mm             = new MakerMapping();
                mm.CreatedBy   = mm.UpdatedBy = 1;
                mm.CreatedDate = mm.UpdatedDate = DateTime.Now;
                mm.MakerId     = viewModel.ID;
            }
            else
            {
                mm.UpdatedDate = DateTime.Now;
            }


            if (viewModel.CompanyName.Equals(AutoMax.Common.Enums.PostingSites.HARAJ.ToString()))
            {
                mm.HarajName = viewModel.EntityNameForCompany;
            }
            else if (viewModel.CompanyName.Equals(AutoMax.Common.Enums.PostingSites.OPENSOUQ.ToString()))
            {
                mm.OpensooqName = viewModel.EntityNameForCompany;
            }

            // add new if not exist
            if (mm.MakerMappingID == 0)
            {
                database.MakerMapping.Add(mm);
            }
        }
Пример #2
0
        // save AutoModel info For Company
        private void AddOrUpdateAutoModelForCompany(AutoMaxContext database, Models.DataModel.MakeMappingViewModel viewModel, Models.DataModel.MappingIDName item)
        {
            AutoModelMapping amm = database.AutoModelMapping.FirstOrDefault(x => x.AutoModelID == item.MappingID);

            if (amm == default(AutoModelMapping))
            {
                amm             = new AutoModelMapping();
                amm.CreatedBy   = amm.UpdatedBy = 1;
                amm.CreatedDate = amm.UpdatedDate = DateTime.Now;
                amm.AutoModelID = item.MappingID;
            }
            else
            {
                amm.UpdatedDate = DateTime.Now;
            }


            if (viewModel.CompanyName.Equals(AutoMax.Common.Enums.PostingSites.HARAJ.ToString()))
            {
                amm.HarajName = item.MappingNameForCompany;
            }
            else if (viewModel.CompanyName.Equals(AutoMax.Common.Enums.PostingSites.OPENSOUQ.ToString()))
            {
                amm.OpensooqName = item.MappingNameForCompany;
            }

            // add new if not exist
            if (amm.AutoModelMappingID == 0)
            {
                database.AutoModelMapping.Add(amm);
            }
        }
Пример #3
0
        public static string GetPostingConfiguration(string name, string defaultvalue = null)
        {
            AutoMaxContext db = new AutoMaxContext();
            var            postingConfiguration = db.PostingConfiguration.FirstOrDefault(p => p.Name == name);

            if (postingConfiguration == null)
            {
                return(defaultvalue);
            }
            else
            {
                return(postingConfiguration.Value);
            }
        }
Пример #4
0
 public UserRepository()
 {
     _db = new AutoMaxContext();
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="GenericRepository{TEntity}"/> class.
 /// </summary>
 /// <param name="context">The context.</param>
 public GenericRepository(AutoMaxContext context)
 {
     this.context = context;
     this.dbSet   = context.Set <TEntity>();
 }
 public void Initialize(AutoMaxContext db, int vehicleId, string postingWebsite)
 {
     this.db             = db;
     this.vehicleId      = vehicleId;
     this.postingWebsite = postingWebsite;
 }
Пример #7
0
        public static string GetFullName(string emil)
        {
            AutoMaxContext db = new AutoMaxContext();

            return(db.Users.Where(d => d.Email == emil).Select(d => new { FullName = d.FirstName + " " + d.LastName }).FirstOrDefault().FullName);
        }
Пример #8
0
        public static string GetUserRole(this string email)
        {
            AutoMaxContext db = new AutoMaxContext();

            return(db.Users.Where(d => d.Email == email).Select(d => d.UserRole.Role).FirstOrDefault());
        }
Пример #9
0
        void executePosting()
        {
            string methodName = "executePosting";

            Library.WriteLog(methodName, "Entered");
            try
            {
                AutoMaxContext db = new AutoMaxContext();

                Library.WriteLog(methodName, "Fetching posting with status 1 (Pending)");
                var postingDetails = db.PostingDetail
                                     .Include("PostingSite")
                                     .Include("VehicleWizard")
                                     .Include("VehicleWizard.VehicleType")
                                     .Include("VehicleWizard.Maker")
                                     .Include("VehicleWizard.AutoModel")
                                     .Include("VehicleWizard.SubModel")
                                     .Include("VehicleWizard.Year")
                                     .Include("VehicleWizard.VehclieTitle")
                                     .Include("VehicleWizard.AutoCondition")
                                     .Include("VehicleWizard.AutoBodyStyle")
                                     .Include("VehicleWizard.AutoAirBag")
                                     .Include("VehicleWizard.AutoInteriorColor")
                                     .Include("VehicleWizard.AutoDoor")
                                     .Include("VehicleWizard.AutoExteriorColor")
                                     .Include("VehicleWizard.AutoEngine")
                                     .Include("VehicleWizard.EngineCapacity")
                                     .Include("VehicleWizard.DriveType")
                                     .Include("VehicleWizard.FuelType")
                                     .Include("VehicleWizard.AutoTransmission")
                                     .Include("VehicleWizard.MediaPlayer")
                                     .Include("VehicleWizard.RoofType")
                                     .Include("VehicleWizard.Upholstery")
                                     .Where(p => p.PostingStatus.StatusName != "Posted" && p.RetryCount < p.Retries).ToList();

                Library.WriteLog(methodName, string.Format("Fetch count {0}", postingDetails.Count), postingDetails.Count > 0 ? LogLevel.Information : LogLevel.Debug);

                foreach (PostingDetail pd in postingDetails)
                {
                    WebsiteBot bot = WebsiteBotFactory.Instance.GetWebsiteBot(pd.PostingSite.PostingSiteName);
                    bot.SetContext(db);
                    bot.SetPostingDetails(pd);

                    if (bot.PostAd())
                    {
                        Library.WriteLog(methodName, "Posting successfull", LogLevel.Information);
                        pd.PostingStatus   = db.PostingStatus.FirstOrDefault(p => p.StatusName == "Posted");
                        pd.UpdatedDate     = DateTime.Now;
                        pd.PostingSiteUser = bot.PostingSiteUser;
                        pd.RetryCount++;
                        pd.PostingError = "Success";
                        db.SaveChanges();
                    }
                    else
                    {
                        Library.WriteLog(methodName, "Posting failed", LogLevel.Information);
                        pd.PostingStatus = db.PostingStatus.FirstOrDefault(p => p.StatusName == "Failed");
                        pd.UpdatedDate   = DateTime.Now;
                        pd.RetryCount++;
                        pd.PostingError = bot.Error;
                        db.SaveChanges();
                    }
                }
                Library.WriteLog(methodName, "Loop completed");
            }
            catch (Exception ex)
            {
                Library.WriteLog(methodName, ex.ToString());
            }
        }