Exemplo n.º 1
0
        public static void CreateNewExternalWebsite(ExternalWebsite website)
        {
            try
            {
                website.DateAdded  = DateTime.Now;
                website.Department = int.Parse(website.SelectedDepartment);
                if (website.Url.StartsWith("http://") || website.Url.StartsWith("https://"))
                {
                }
                else
                {
                    website.Url = website.Url.Insert(0, "http://");
                }
            }
            catch
            {
                return;
            }

            using (FreeMarketEntities db = new FreeMarketEntities())
            {
                db.ExternalWebsites.Add(website);
                db.SaveChanges();
            }
        }
Exemplo n.º 2
0
        public static ExternalWebsite GetNewWebsite()
        {
            ExternalWebsite website = new ExternalWebsite();

            website.DateAdded = DateTime.Now;

            using (FreeMarketEntities db = new FreeMarketEntities())
            {
                website.Departments = db.Departments
                                      .Select(c => new SelectListItem
                {
                    Text  = "(" + c.DepartmentNumber + ")" + c.DepartmentName,
                    Value = c.DepartmentNumber.ToString()
                })
                                      .ToList();
            }

            return(website);
        }
Exemplo n.º 3
0
        public static ExternalWebsite GetWebsite(int websiteNumber)
        {
            ExternalWebsite website = new ExternalWebsite();

            using (FreeMarketEntities db = new FreeMarketEntities())
            {
                var websiteInfo = db.ExternalWebsites.Find(websiteNumber);

                if (websiteInfo == null)
                {
                    return(website);
                }
                else
                {
                    website = websiteInfo;
                }

                website.MainImageNumber = db.ExternalWebsitePictures
                                          .Where(c => c.WebsiteNumber == website.LinkId && c.Dimensions == PictureSize.Medium.ToString())
                                          .Select(c => c.PictureNumber)
                                          .FirstOrDefault();

                website.AdditionalImageNumber = db.ExternalWebsitePictures
                                                .Where(c => c.WebsiteNumber == website.LinkId && c.Dimensions == PictureSize.Large.ToString())
                                                .Select(c => c.PictureNumber)
                                                .FirstOrDefault();

                website.Departments = db.Departments
                                      .Select(c => new SelectListItem
                {
                    Text     = "(" + c.DepartmentNumber + ") " + c.DepartmentName,
                    Value    = c.DepartmentNumber.ToString(),
                    Selected = c.DepartmentNumber == website.Department ? true : false
                })
                                      .ToList();
            }

            return(website);
        }
Exemplo n.º 4
0
        public static void SaveExternalWebsite(ExternalWebsite website)
        {
            using (FreeMarketEntities db = new FreeMarketEntities())
            {
                try
                {
                    if (website.Url.StartsWith("http://") || website.Url.StartsWith("https://"))
                    {
                    }
                    else
                    {
                        website.Url = website.Url.Insert(0, "http://");
                    }

                    website.Department      = int.Parse(website.SelectedDepartment);
                    db.Entry(website).State = EntityState.Modified;
                    db.SaveChanges();
                }
                catch (Exception e)
                {
                    ExceptionLogging.LogException(e);
                }
            }
        }