Esempio n. 1
0
 public ProductAgeDto get(string id)
 {
     try
     {
         ProductAge bb = _context.ProductAge.Find(id);
         //               _context.Entry(bb).Reference(b => b.ProductAge).Load();
         //              _context.Entry(bb).Reference(b => b.Province).Load();
         return(mapper.Map <ProductAge, ProductAgeDto>(bb));
     }
     catch (Exception)
     {
         return(null);
     }
 }
Esempio n. 2
0
        public string create(ProductAgeDto tProductAgeDto)
        {
            try
            {
                ProductAge tProductAgeNew = mapper.Map <ProductAgeDto, ProductAge>(tProductAgeDto);
                tProductAgeNew.Id         = Guid.NewGuid().ToString();
                tProductAgeNew.CreateDate = DateTime.Now;

                _context.ProductAge.Add(tProductAgeNew);
                _context.SaveChanges();
                return("0");
            }
            catch (Exception)
            {
                return("1");
            }
        }
Esempio n. 3
0
        public string delete(string id)
        {
            try
            {
                ProductAge tProductAgeBranchRemove = _context.ProductAge.Find(id);
                if (tProductAgeBranchRemove == null)
                {
                    return("1");
                }

                _context.ProductAge.Remove(tProductAgeBranchRemove);
                _context.SaveChanges();
                return("0");
            }
            catch (Exception)
            {
                return("1");
            }
        }
Esempio n. 4
0
        public string lockItem(string id)
        {
            try
            {
                ProductAge tProductAgeBranchBlock = _context.ProductAge.Find(id);
                if (tProductAgeBranchBlock == null)
                {
                    return("1");
                }
                tProductAgeBranchBlock.Status = false;

                _context.ProductAge.Update(tProductAgeBranchBlock);
                _context.SaveChanges();
                return("0");
            }
            catch (Exception)
            {
                return("1");
            }
        }
Esempio n. 5
0
        public string update(ProductAgeDto tProductAgeDto)
        {
            try
            {
                ProductAge tProductAgeBranchUpdate = _context.ProductAge.Find(tProductAgeDto.Id);
                if (tProductAgeBranchUpdate == null)
                {
                    return("1");
                }
                tProductAgeBranchUpdate.Id         = tProductAgeDto.Id;
                tProductAgeBranchUpdate.Name       = tProductAgeDto.Name;
                tProductAgeBranchUpdate.Status     = tProductAgeDto.Status;
                tProductAgeBranchUpdate.CreateDate = tProductAgeDto.CreateDate;


                _context.ProductAge.Update(tProductAgeBranchUpdate);
                _context.SaveChanges();
                return("0");
            }
            catch (Exception)
            {
                return("1");
            }
        }
Esempio n. 6
0
        private void ImportProduct(Item item, BackgroundWorker worker)
        {
            try {
                SupplierProduct suppProd = null;
                //Set up the main COMP record
                bool productAddedOrNameChanged = false;
                var  comp = _context.COMP
                            .Include(c => c.ProductAge)
                            .Include(c => c.SupplierProductAge)
                            .Include(c => c.SupplierProduct)
                            .FirstOrDefault(c => c.CODE == item.InternalCode);
                if (comp == null)
                {
                    productAddedOrNameChanged = true;
                    comp = new COMP()
                    {
                        CODE                  = item.InternalCode,
                        NAME                  = item.Name,
                        RSTR_CDE              = "O",
                        Inactive              = "N",
                        AdminClosed           = false,
                        PickupInfoRequired    = false,
                        DropoffInfoRequired   = false,
                        VendorPrepayReqd      = false,
                        AccountingServiceItem = true,
                        MealsIncluded         = false,
                        RATE_BASIS            = "D",
                        ProximitySearch       = false,
                        WeightRequired        = false,
                        DOBRequired           = false,
                        Allow_Freesell        = false,
                        Multiple_Times        = "0",
                        SERV_TYPE             = searchLookUpEditServiceType.EditValue.ToString(),
                        CITY                  = searchLookUpEditCity.EditValue.ToString()
                    };
                    _context.COMP.AddObject(comp);
                }
                else
                {
                    if (comp.AdminClosed || comp.Inactive == "Y")
                    {
                        return;
                    }
                    suppProd = comp.SupplierProduct.FirstOrDefault(sp => sp.Supplier_GUID == _supplierConnection.Supplier_GUID &&
                                                                   sp.ProductCodeSupplier == item.Pk.ToString());
                }
                if (suppProd == null)
                {
                    suppProd = new SupplierProduct()
                    {
                        Product_Type          = "OPT",
                        Product_Code_Internal = item.InternalCode,
                        ProductCodeSupplier   = item.Pk.ToString(),
                        Supplier_GUID         = _supplierConnection.Supplier_GUID,
                        Inactive = false,
                    };
                    suppProd.COMP = comp;
                    _context.SupplierProduct.AddObject(suppProd);
                }
                suppProd.Custom1          = _company;
                suppProd.SupplierCommPct  = spinEditCommPct.Value;
                suppProd.SupplierCommFlat = spinEditCommFlat.Value;
                suppProd.MarkupPct        = spinEditMarkupPct.Value;
                suppProd.MarkupFlat       = spinEditMarkupFlat.Value;

                //Don't overwrite name because staff change it manually
                //if (comp.NAME != item.Name) {
                //    productAddedOrNameChanged = true;
                //}
                //comp.NAME = item.Name;
                if (item.Is_pickup_ever_available)
                {
                    comp.PUDRP_REQ = "P";
                    comp.TRSFR_TYP = "O";
                }
                else
                {
                    comp.TRSFR_TYP = "N";
                }
                comp.StartingPrice    = item.StartingPrice;
                comp.StartingCost     = Math.Round(item.StartingPrice * (1 - ((suppProd.SupplierCommPct ?? 0) / 100)), 2) - (suppProd.SupplierCommFlat ?? 0);
                comp.StartingAgentNet = Math.Round((comp.StartingCost ?? 0) * (1 + ((suppProd.MarkupPct ?? 0) / 100)), 2) - (suppProd.MarkupFlat ?? 0);
                //Other location types seem to be "pre", "start", "end"
                //TODO: Each location can also have notes, which are rarely provided and often duplicate other information
                //Should the location notes be stored somewhere?
                //There is also an item.Location property which holds the whole address as a single string
                var mainLocation = item.Locations.FirstOrDefault(l => l.Type == "primary");
                if (mainLocation == null)
                {
                    mainLocation = item.Locations.FirstOrDefault();
                }
                if (mainLocation != null)
                {
                    var address = mainLocation.Address;
                    comp.ADDR1   = address.Street;
                    comp.COUNTRY = address.Country;
                    comp.ZIP     = address.Postal_code;
                    comp.STATE   = address.Province;
                    comp.TOWN    = address.City;
                    if (mainLocation.Latitude != null && mainLocation.Longitude != null)
                    {
                        var geo = comp.GeoCode;
                        if (geo == null)
                        {
                            geo = new GeoCode();
                            _context.GeoCode.AddObject(geo);
                            comp.GeoCode = geo;
                        }
                        geo.AgentInitials = _sys.User.Name;
                        geo.PushLat       = (double)mainLocation.Latitude;
                        geo.PushLong      = (double)mainLocation.Longitude;
                    }
                }

                if (Configurator.ImportCancellationPolicies)
                {
                    //Cancellation policy has a type field which so far is only ever "hours-before-start"
                    int daysPrior = (int)Math.Ceiling(item.Effective_cancellation_policy.Cutoff_hours_before / 24) + (_supplierConnection.ExtraNightsPriorForCxlPolicy ?? 0);
                    FindOrAddCxlfee(_sys, _context, comp.CODE, daysPrior, 100);
                }

                //Set up the age mappings
                foreach (var custType in item.Customer_prototypes.Where(cp => cp.Selected))
                {
                    SupplierProductAge suppProdAge = null;
                    ProductAge         prodAge     = null;
                    if (custType.InternalId != null)
                    {
                        suppProdAge = comp.SupplierProductAge.FirstOrDefault(sp => sp.Id == custType.InternalId);
                    }
                    if (suppProdAge == null)
                    {
                        suppProdAge = new SupplierProductAge()
                        {
                            Product_Code  = comp.CODE,
                            Product_Type  = "OPT",
                            Supplier_GUID = _supplierConnection.Supplier_GUID,
                            SupplierId    = custType.Pk.ToString()
                        };
                        _context.SupplierProductAge.AddObject(suppProdAge);
                    }
                    else
                    {
                        prodAge = suppProdAge.ProductAge;
                    }
                    if (prodAge == null)
                    {
                        //If there is already a ProductAge record with the same age limits, reuse it rather than creating a new one
                        prodAge = comp.ProductAge.FirstOrDefault(pa => pa.FromAge == custType.FromAge && pa.ToAge == custType.ToAge);
                        if (prodAge == null)
                        {
                            prodAge = new ProductAge()
                            {
                                Product_Type = "OPT",
                                Product_Code = comp.CODE,
                            };
                            comp.ProductAge.Add(prodAge);
                            _context.ProductAge.AddObject(prodAge);
                        }
                    }
                    suppProdAge.SupplierName = custType.Display_name;
                    prodAge.FromAge          = custType.FromAge;
                    prodAge.ToAge            = custType.ToAge;
                    prodAge.Description      = custType.PaxType;
                    switch (custType.PaxType.ToLower())
                    {
                    case "adult":
                        prodAge.PluralDescription = "Adults";
                        break;

                    case "child":
                        prodAge.PluralDescription = "Children";
                        break;

                    case "junior":
                        prodAge.PluralDescription = "Juniors";
                        break;

                    case "infant":
                        prodAge.PluralDescription = "Infants";
                        break;

                    case "senior":
                        prodAge.PluralDescription = "Seniors";
                        break;
                    }
                    if (custType.ToAge == null || custType.ToAge >= 18)
                    {
                        prodAge.IsAdult      = true;
                        prodAge.TreatAsAdult = true;
                    }
                    suppProdAge.ProductAge = prodAge;
                }

                //Set up the media information
                MEDIAINFO mainInfo = MediaHelper.CheckAndCreateNewMediaInfo(_context, _sys.Settings.MainMediaSection, item.Name,
                                                                            "OPT", comp.CODE, string.Empty, "ENG", Configurator.CreateNewInfoAsInHouse, null);

                List <string> texts = new List <string>();
                if (!string.IsNullOrEmpty(item.Headline))
                {
                    texts.Add(item.Headline);
                }
                if (!string.IsNullOrEmpty(item.Description_text))
                {
                    texts.Add(item.Description_text);
                }
                if (!string.IsNullOrEmpty(item.Description_safe_html))
                {
                    texts.Add(item.Description_safe_html);
                }
                string.Join("<br/><br/>", texts);
                mainInfo.TEXT = item.Headline + item.Description_text + item.Description_safe_html;
                string imagePath = MediaHelper.GetOrPutImage(_sys, "OPT", comp.CODE, _prefix, comp.CITY, item.Image_cdn_url, string.Empty, false);
                mainInfo.IMAGE1 = imagePath;
                imagePath       = MediaHelper.GetOrPutImage(_sys, "OPT", comp.CODE, _prefix, comp.CITY, item.Image_cdn_url, "thumb_", true);
                mainInfo.IMAGE4 = imagePath;

                //Some companies have booking notes that are clearly intended for after making a booking because they say
                //"Thank you for your booking". Others have useful info about what to bring and what to expect. We can't tell the difference
                //so just always use the booking notes
                MEDIAINFO fullInfo = MediaHelper.CheckAndCreateNewMediaInfo(_context, Configurator.FullDescMediaReportSection, _fullDescTitles[0],
                                                                            "OPT", comp.CODE, string.Empty, "ENG", Configurator.CreateNewInfoAsInHouse, null);
                fullInfo.TEXT = CreateBulletList(item.Description_bullets) + item.Booking_notes_safe_html;

                MEDIAINFO termsInfo = new MEDIAINFO();
                if (!string.IsNullOrEmpty(item.Cancellation_policy_safe_html))
                {
                    termsInfo = MediaHelper.CheckAndCreateNewMediaInfo(_context, Configurator.TermsMediaReportSection, _termsTitles[0],
                                                                       "OPT", comp.CODE, string.Empty, "ENG", Configurator.CreateNewInfoAsInHouse, null);
                    termsInfo.TEXT = item.Cancellation_policy_safe_html;
                }

                //Download the images and attach to the main media section
                List <RESOURCE> resources = new List <RESOURCE>();
                if (Configurator.DownloadImages)
                {
                    foreach (var image in item.Images)
                    {
                        imagePath = MediaHelper.GetOrPutImage(_sys, "OPT", comp.CODE, _prefix, comp.CITY, image.Image_cdn_url, string.Empty, false);
                        MediaHelper.CheckAndAddResource(_context, resources, mainInfo, imagePath, string.Empty, "1");       //1=medium res
                    }
                }

                var rptGeninfo = MediaHelper.CheckAndCreateNewMediaRpt(_context, _sys.Settings.MainMediaReport, "OPT", comp.CODE,
                                                                       "ENG", null);
                var rptVoucher = MediaHelper.CheckAndCreateNewMediaRpt(_context, Configurator.VoucherMediaReportType, "OPT", comp.CODE,
                                                                       "ENG", null);

                if ((!string.IsNullOrEmpty(mainInfo.TEXT) || resources.Count > 0))
                {
                    MediaHelper.CheckAndAddInfoToReports(_context, new MEDIARPT[] { rptGeninfo, rptVoucher }, mainInfo, 0);
                    if (mainInfo.ID == 0)
                    {
                        _context.MEDIAINFO.AddObject(mainInfo);
                    }
                }
                if (!string.IsNullOrEmpty(fullInfo.TEXT))
                {
                    MediaHelper.CheckAndAddInfoToReports(_context, new MEDIARPT[] { rptGeninfo }, fullInfo, 1);
                    if (fullInfo.ID == 0)
                    {
                        _context.MEDIAINFO.AddObject(fullInfo);
                    }
                }
                if (!string.IsNullOrEmpty(termsInfo.TEXT))
                {
                    MediaHelper.CheckAndAddInfoToReports(_context, new MEDIARPT[] { rptGeninfo, rptVoucher }, termsInfo, 2);
                    if (termsInfo.ID == 0)
                    {
                        _context.MEDIAINFO.AddObject(termsInfo);
                    }
                }
                if (rptGeninfo.ID == 0 && rptGeninfo.MediaRptItem.Count > 0)
                {
                    _context.MEDIARPT.AddObject(rptGeninfo);
                }
                if (rptVoucher.ID == 0 && rptVoucher.MediaRptItem.Count > 0)
                {
                    _context.MEDIARPT.AddObject(rptVoucher);
                }

                List <MEDIAINFO> infos = new List <MEDIAINFO>()
                {
                    mainInfo, fullInfo, termsInfo
                };
                MediaHelper.SetMediaInfosChgDate(_context, infos, _update);
                MediaHelper.SetServiceChgDate(_context, comp, _update, _sys.User.Name);

                _context.SaveChanges();
                if (productAddedOrNameChanged)
                {
                    AccountingAPI.InvokeForProduct(_sys.Settings.TourAccountingURL, "OPT", comp.CODE);
                }

                //Update the image resources with the id of the linked media section
                if (resources.Count > 0)
                {
                    foreach (var resource in resources)
                    {
                        resource.LINK_VALUE = mainInfo.ID.ToString();
                        _context.RESOURCE.AddObject(resource);
                    }
                    _context.SaveChanges();
                }

                try {
                    worker.ReportProgress(0, $"Updating website for {item.Name}");
                    _context.usp_RefreshSingleProduct("OPT", comp.CODE, _sys.Settings.MainMediaReport, _sys.Settings.FeaturedMediaSection,
                                                      _sys.Settings.MainMediaReport, _sys.Settings.MainMediaSection);
                }
                catch {
                    NLog.LogManager.GetCurrentClassLogger().Trace(" Refresh Product Failed");
                }
            }
            catch (DbEntityValidationException ex) {
                string details = string.Join(Environment.NewLine, ex.EntityValidationErrors.Select(e =>
                                                                                                   string.Join(Environment.NewLine, e.ValidationErrors.Select(v =>
                                                                                                                                                              string.Format("{0} - {1}", v.PropertyName, v.ErrorMessage)))));
                details += Environment.NewLine;
                NLog.LogManager.GetCurrentClassLogger().Error(ex, details);
                System.Diagnostics.Debugger.Break();
            }
            catch (Exception ex) {
                NLog.LogManager.GetCurrentClassLogger().Error(ex);
                System.Diagnostics.Debugger.Break();
            }
        }