Beispiel #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);
            }
        }
Beispiel #2
0
        public ActionResult AddMakeMapping(Models.DataModel.MakeMappingViewModel viewModel)
        {
            ActionResult result;

            try
            {
                AddOrUpdateMakerInfoForCompany(db, viewModel);

                if (viewModel.MappingIDNames != null && viewModel.MappingIDNames.Any())
                {
                    foreach (Models.DataModel.MappingIDName item in viewModel.MappingIDNames)
                    {
                        AddOrUpdateAutoModelForCompany(db, viewModel, item);
                    }
                }

                // commit changes
                db.SaveChanges();
                SetFlashMessage("Mapping has been successfully saved.");
            }
            catch (Exception ex)
            {
                SetFlashMessage("Some error occured. Error : " + ex.ToString(), isError: true);
            }

            result = RedirectToAction("MakeMapping", new { companyName = viewModel.CompanyName });
            return(result);
        }
Beispiel #3
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);
            }
        }
Beispiel #4
0
        public ActionResult AddMakeMapping(string companyName, int ID)
        {
            ActionResult result = RedirectToAction("PublishItem");

            Models.DataModel.MakeMappingViewModel viewModel = new Models.DataModel.MakeMappingViewModel();
            viewModel.CompanyName = companyName;
            viewModel.ID          = ID;

            // load Maker info
            Maker entity = db.Makers.FirstOrDefault(x => x.MakerID == ID);

            if (entity != default(Maker))
            {
                viewModel.EntityName = entity.Name;

                // load and sets Maker mapping for Company if exist
                MakerMapping entityMapping = db.MakerMapping.FirstOrDefault(x => x.MakerId == ID);
                if (entityMapping != default(MakerMapping))
                {
                    if (companyName.Equals(AutoMax.Common.Enums.PostingSites.HARAJ.ToString()))
                    {
                        viewModel.EntityNameForCompany = entityMapping.HarajName;
                    }
                    else if (companyName.Equals(AutoMax.Common.Enums.PostingSites.OPENSOUQ.ToString()))
                    {
                        viewModel.EntityNameForCompany = entityMapping.OpensooqName;
                    }
                }
                var autoModels            = db.AutoModels.Where(x => x.MakerID == entity.MakerID).ToList();
                var autoModelIDs          = autoModels.Select(x => x.AutoModelID).ToList();
                var autoModelsWithMapping = db.AutoModelMapping.Where(x => autoModelIDs.Contains(x.AutoModelID)).ToList();

                viewModel.MappingIDNames = new List <Models.DataModel.MappingIDName>();
                foreach (var item in autoModels)
                {
                    var map = autoModelsWithMapping.FirstOrDefault(x => x.AutoModelID == item.AutoModelID);
                    viewModel.MappingIDNames.Add(new Models.DataModel.MappingIDName
                    {
                        MappingID             = item.AutoModelID,
                        MappingName           = item.ModelName,
                        MappingNameForCompany = (map != null ? (companyName.Equals(AutoMax.Common.Enums.PostingSites.HARAJ.ToString()) ? map.HarajName : map.OpensooqName) : "")
                    });
                }

                result = View(viewModel);
            }
            return(result);
        }