public ActionResult DownloadFile(string Id)
        {
            DBDataContext db = new DBDataContext();

            int IdCur = Convert.ToInt32(Id);
            EducationSearching.Files fFile = db.Files.FirstOrDefault(u => u.Id == IdCur);
            FileContentResult tr = new FileContentResult(fFile.FileData.ToArray(), fFile.MimeType);
            tr.FileDownloadName = fFile.Name;
            return tr;
        }
Пример #2
0
        //
        // GET: /Admin/
        public ActionResult Index()
        {
            DBDataContext db = new DBDataContext();
            UserProfile user = db.UserProfile.FirstOrDefault(u => u.UserName.ToLower() == User.Identity.Name.ToLower());
            ViewBag.UserFIO = user.FIOShort;
            if (user == null)
            {
                ViewBag.UserRole = "Anonymous";
                return View();
            }
            webpages_UsersInRoles userInRoles = db.webpages_UsersInRoles.FirstOrDefault(u => u.UserId == user.UserId);
            if (userInRoles == null)
            {
                ViewBag.UserRole = "Anonymous";
                return View();
            }
            webpages_Roles roles = db.webpages_Roles.FirstOrDefault(u => u.RoleId == userInRoles.RoleId);
            if (roles == null)
            {
                ViewBag.UserRole = "Anonymous";
                return View();
            }

            if (!string.Equals(roles.RoleName, "Administrator"))
            {
                return RedirectToAction("Index", "Main");
            }
            return View();
        }
Пример #3
0
    public void OnNewsChanged(object sender, EventArgs e)
    {
        using (DBDataContext db = new DBDataContext())
        {
            int mId = 0;
            int.TryParse(ddlNews.SelectedValue, out mId);

            var p = (from N in db.News
                     where N.id == mId
                     select N).FirstOrDefault();
            if (p != null)
            {
                txtHeader.Text = p.Header;
                txtPageTitle.Text = p.PageHeader;
                fckEditor.Value = p.Content;
                btnSave.Text = "Обновить новость";
                btnDelete.Enabled = true;
            }
            else
            {
                btnSave.Text = "Добавить новость";
                btnDelete.Enabled = false;
            }
        }
    }
Пример #4
0
 public void OnAdd(object sender, EventArgs e)
 {
     if (Page.IsValid)
     {
         if (ddlNews.SelectedValue == "-1")
         {
             using (DBDataContext db = new DBDataContext())
             {
                 var news = new News()
                 {
                     Header = txtHeader.Text.Trim(),
                     PageHeader = txtPageTitle.Text.Trim(),
                     Content = fckEditor.Value
                 };
                 db.News.InsertOnSubmit(news);
                 db.SubmitChanges();
                 lblMessage.Text = string.Format("Добавлена новая новость '{0}'", txtHeader.Text.Trim());
             }
         }
         else
         {
             Update();
         }
         InitLists();
     }
 }
Пример #5
0
    public void OnAdd(object sender, EventArgs e)
    {
        if (Page.IsValid)
        {
            using (DBDataContext db = new DBDataContext())
            {
                int catID = int.Parse(ddlCategories.SelectedValue);
                var qa = new QA()
                {
                    Quester = txtName.Text.Trim(),
                    Question = txtQuestion.Text.Trim(),
                    Header = txtQuestion.Text.Trim(),
                    Phone = string.IsNullOrEmpty(txtPhone.Text.Trim()) ? null : txtPhone.Text.Trim(),
                    Date = DateTime.Now,
                    CategoryId = catID
                };
                db.QA.InsertOnSubmit(qa);
                db.SubmitChanges();

                mvQA.SetActiveView(vQuestion);
                txtName.Text = "";
                txtQuestion.Text = "";
                txtPhone.Text = "";

                lblMessage.Text = "Спасибо за Ваш вопрос. В ближайшее время мы постараемся дать Вам ответ.";
            }
        }
    }
Пример #6
0
 protected void lvCities_ItemUpdating(object sender, ListViewUpdateEventArgs e)
 {
     using (DBDataContext db = new DBDataContext())
     {
       string name = "";
       int ID = 0, DeliveryPrice = 0, FreeDelivery = 0;
       foreach (string key in e.NewValues.Keys)
       {
     switch(key)
     {
       case "Name":
         name = e.NewValues[key].ToString();
         break;
       case "DeliveryPrice":
         int.TryParse(e.NewValues[key].ToString(), out DeliveryPrice);
         break;
       case "FreeDelivery":
         int.TryParse(e.NewValues[key].ToString(), out FreeDelivery);
         break;
       case "ID":
         int.TryParse(e.NewValues[key].ToString(), out ID);
         break;
     }
       }
       City c = db.Cities.First(C => C.ID == ID);
       c.Name = name;
       c.FreeDelivery = FreeDelivery;
       c.DeliveryPrice = DeliveryPrice;
       db.SubmitChanges();
     }
     lvCities.EditIndex = -1;
 }
Пример #7
0
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Session["searchString"] != null)
        {
            string s = Session["searchString"].ToString();
            using (DBDataContext db = new DBDataContext())
            {
                var q = from Q in db.QA
                        where Q.Answer.Contains(s) || Q.Header.Contains(s) || Q.Question.Contains(s)
                        select new
                        {
                            Link = ResolveUrl(string.Format("~/QuestionAnswer.aspx?id={0}", Q.id)),
                            Header = Q.Header
                        };
                var p = from P in db.Pages
                        where P.Content.Contains(s) || P.DisplayLinkTitle.Contains(s) || P.Title.Contains(s)
                        select new
                        {
                            Link = ResolveUrl(string.Format("~/Page.aspx?id={0}", P.id)),
                            Header = P.Title
                        };

                var b = from B in db.Blog
                        where B.Content.Contains(s) || B.Header.Contains(s)
                        select new
                        {
                            Link = ResolveUrl(string.Format("~/Blog.aspx?id={0}", B.id)),
                            Header = B.Header
                        };

                lvSearchResults.DataSource = q.Union(p).Union(b);
                lvSearchResults.DataBind();
            }
        }
    }
Пример #8
0
 protected void Page_Load(object sender, EventArgs e)
 {
     //Response.Redirect("/Developing.htm");
     using (DBDataContext db = new DBDataContext())
     {
       City[] cityList = (from CITY in db.Cities
                      orderby CITY.Name
                      select CITY).ToArray();
       ddlCities.DataSource = cityList;
       ddlCities.DataTextField = "Name";
       ddlCities.DataValueField = "ID";
       ddlCities.DataBind();
       foreach (ListItem li in ddlCities.Items)
       {
     li.Attributes.Add("dLimit", cityList.Where(C => C.ID == int.Parse(li.Value)).First().FreeDelivery.ToString());
     if (li.Value == Cart.SelectedCity)
     {
       li.Selected = true;
       txtDeliveryLimit.InnerText = li.Attributes["dLimit"];
     }
       }
       if (Request.Cookies["selectedCityToDeliver"] == null && ddlCities.Items.Count > 0)
       {
     txtDeliveryLimit.InnerText = ddlCities.Items[0].Attributes["dLimit"];
       }
     }
     CartResponse cr = new CartResponse();
     cartTotal.InnerHtml = cr.price.ToString();
     cartCount.InnerHtml = cr.count.ToString();
 }
Пример #9
0
    public void OnDelete(object sender, EventArgs e)
    {
        LinkButton btn = (LinkButton)sender;
        int i = 0;
        int.TryParse(btn.CommandArgument, out i);
        if (i != 0)
        {
            using (DBDataContext db = new DBDataContext())
            {
                var q = (from Q in db.QA
                         where Q.id == i
                         select Q).FirstOrDefault();
                if (q != null)
                {
                    db.QA.DeleteOnSubmit(q);
                    db.SubmitChanges();

                    lblMessage.Text = "Ответ успешно удален.";
                    mvQuestions.SetActiveView(vNotAnswered);

                    var data = (from Q in db.QA
                                where !Q.Answered
                                select Q).ToArray();
                    lvNotAnswered.DataSource = data;
                    lvNotAnswered.DataBind();
                }
                else
                    lblMessage.Text = "Ошибка при удалении.";
            }
        }
        else
        {
            lblMessage.Text = "Ошибка при удалении.";
        }
    }
Пример #10
0
        public void GenerateCodeTest()
        {
            using (var db = new DBDataContext())
            {
                var appClient = db.Client.Where(a => a.Deleted == 0).FirstOrDefault();
                var userAccount = db.Account.Where(e => e.Deleted == 0).FirstOrDefault();
                if (appClient != null && userAccount != null)
                {
                    var client = new ClientDao().GetClient(appClient.ID);

                    var code = Core.Instance.AuthManager.GenerateCode(client, userAccount);

                    Assert.AreNotEqual(null, code);

                    var token = Core.Instance.AuthManager.GetAccessToken(new AuthorizeCode
                    {
                        AccountId = userAccount.AccountId,
                        ClientId = client.ClientId,
                        CreateTime = DateTime.Now
                    });

                    Assert.AreNotEqual(null, token);

                    var values = token.Token.FromHexString().AESDecrypt().Split('|');

                    Assert.AreEqual(values[0], client.ClientId);
                }
            }
        }
Пример #11
0
 public void OnLink(object sender, EventArgs e)
 {
     if (Page.IsValid)
     {
         using (DBDataContext db = new DBDataContext())
         {
             int pid = 0;
             int mid = 0;
             if (int.TryParse(ddlMenu.SelectedValue, out mid) && int.TryParse(ddlPage.SelectedValue, out pid))
             {
                 var p = (from P in db.Pages
                          where P.id == pid
                          select P).FirstOrDefault();
                 var m = (from M in db.LeftMenu
                          where M.id == mid
                          select M).FirstOrDefault();
                 if (p != null && m != null)
                 {
                     m.PageID = p.id;
                     db.SubmitChanges();
                     lblMessage.Text = string.Format("Пункт меню '{0}' был успешно связан со страницей '{1}'", m.ItemName, p.Title);
                 }
             }
         }
     }
 }
Пример #12
0
 public void OnLink(object sender, EventArgs e)
 {
     if (Page.IsValid)
     {
         using (DBDataContext db = new DBDataContext())
         {
             int mid = 0;
             if (int.TryParse(ddlMenu.SelectedValue, out mid))
             {
                 var m = from M in db.LeftMenu
                          select M;
                 foreach (ListItem I in cblSubmenu.Items)
                 {
                     foreach (var M in m)
                     {
                         if (M.id.ToString() == I.Value)
                         {
                             if (I.Selected)
                                 M.ParetnId = mid;
                             else
                                 M.ParetnId = null;
                         }
                     }
                 }
                 db.SubmitChanges();
                 lblMessage.Text = "Сохранено";
             }
         }
     }
 }
Пример #13
0
 public void OnMenuChanged(object sender, EventArgs e)
 {
     using (DBDataContext db = new DBDataContext())
     {
         var menudata = from LM in db.LeftMenu
                        orderby LM.Order
                        select LM;
         int i;
         if (int.TryParse(ddlMenu.SelectedValue, out i))
         {
             cblSubmenu.Items.Clear();
             foreach (var sd in menudata)
             {
                 if (sd.id != i && (sd.ParetnId == i || sd.ParetnId == null))
                 {
                     ListItem l = new ListItem();
                     l.Selected = sd.ParetnId == i;
                     l.Text = sd.ItemName;
                     l.Value = sd.id.ToString();
                     cblSubmenu.Items.Add(l);
                 }
             }
         }
     }
 }
Пример #14
0
    private void InitLists()
    {
        using (DBDataContext db = new DBDataContext())
        {
            var menudata = from LM in db.LeftMenu
                           orderby LM.Order
                           select LM;

            ddlMenu.DataSource = menudata;
            ddlMenu.DataTextField = "ItemName";
            ddlMenu.DataValueField = "id";
            ddlMenu.DataBind();
            int i;
            if (int.TryParse(ddlMenu.SelectedValue, out i))
            {
                cblSubmenu.Items.Clear();
                foreach (var sd in menudata)
                {
                    if (sd.id != i && (sd.ParetnId == i || sd.ParetnId == null))
                    {
                        ListItem l = new ListItem();
                        l.Selected = sd.ParetnId == i;
                        l.Text = sd.ItemName;
                        l.Value = sd.id.ToString();
                        cblSubmenu.Items.Add(l);
                    }
                }
            }
        }
    }
Пример #15
0
 public void OnDown(object sender, EventArgs e)
 {
     int i = 0;
     if (int.TryParse(ddlMenu.SelectedValue, out i))
     {
         using (DBDataContext db = new DBDataContext())
         {
             var m = (from M in db.LeftMenu
                      where M.id == i
                      select M).FirstOrDefault();
             if (m != null)
             {
                 var exm = (from EXM in db.LeftMenu
                            where EXM.Order > m.Order
                            orderby EXM.Order
                            select EXM).FirstOrDefault();
                 if (exm != null)
                 {
                     int tmp = m.Order.Value;
                     m.Order = exm.Order.Value;
                     exm.Order = tmp;
                     db.SubmitChanges();
                 }
             }
         }
     }
 }
Пример #16
0
 protected void Page_PreRender(object sender, EventArgs e)
 {
     using (DBDataContext db = new DBDataContext())
     {
         var m = (from TM in db.LeftMenu
                  where TM.ParetnId == null
                  orderby TM.Order
                  select new
                  {
                      Title = TM.ItemName,
                      Alt = "",
                      Link = TM.PageID,
                      SubMenu = TM.LeftMenu2.ToList()
                  }).ToList();
         var res = from M in m
                   select new
                   {
                       M.Alt,
                       M.Title,
                       Link = !M.Link.HasValue ? "#" : string.Format(ResolveUrl("~/Page.aspx?id={0}"), M.Link.Value),
                       Submenu = M.SubMenu
                   };
         lvLeftMenu.DataSource = res;
         lvLeftMenu.DataBind();
     }
 }
Пример #17
0
 protected void Page_Load(object sender, EventArgs e)
 {
     int id;
     if (int.TryParse(Request["id"], out id))
     {
         mvNewsView.SetActiveView(vSingle);
         using (DBDataContext db = new DBDataContext())
         {
             var n = (from N in db.News
                      where N.id == id
                      select N).FirstOrDefault();
             if (n != null)
             {
                 Page.Title = n.PageHeader;
                 lblContent.Text = n.Content;
                 h2NewsHeader.InnerText = n.Header;
             }
             else
                 lblContent.Text = "Новость была удалена с сервера.";
         }
     }
     else
     {
         mvNewsView.SetActiveView(vAll);
         using (DBDataContext db = new DBDataContext())
         {
             var res = (from N in db.News
                        select N).ToList();
             lvNews.DataSource = res;
             lvNews.DataBind();
             if (res.Count() <= dpPager.PageSize)
                 dpPager.Visible = false;
         }
     }
 }
Пример #18
0
 protected void Edit(int id)
 {
     using (DBDataContext db = new DBDataContext())
     {
       Item itm = db.Items.FirstOrDefault(I => I.ID == id);
       if (itm != null)
       {
     txtDescription.Text = itm.Description.Trim();
     txtShortDescription.Text = itm.ShortDescription;
     txtName.Text = itm.Name.Trim();
     txtPrice.Text = itm.Price.ToString();
     txtWeight.Text = itm.Weight.ToString();
     ddlCategory.ClearSelection();
     ddlCategory.Items.FindByValue(itm.Category.ToString()).Selected = true;
     ddlRez.ClearSelection();
     if (itm.Rezba.HasValue)
       ddlRez.Items.FindByValue(itm.Rezba.ToString()).Selected = true;
     ddlSize.ClearSelection();
     if (itm.Size.HasValue)
       ddlSize.Items.FindByValue(itm.Size.ToString()).Selected = true;
     lvImages.DataSource = itm.Pics;
     lvImages.DataBind();
     lblItemsCount.Text = itm.IncomeOrders.Sum(IO => IO.ItemsLeft).ToString();
     txtIncomePricePerItem.Text = ((int)Math.Round(itm.Price * Cart.Currency)).ToString();
       }
       else
     Response.Redirect("/admin/Default.aspx");
     }
     mvItems.SetActiveView(vEdit);
 }
Пример #19
0
 protected void Page_Load(object sender, EventArgs e)
 {
     int id = 0;
     if (int.TryParse(Request["id"], out id))
     {
         mvBlog.SetActiveView(vSingle);
         using (DBDataContext db = new DBDataContext())
         {
             var b = (from B in db.Blog
                      where B.id == id
                      select B).FirstOrDefault();
             if (b != null)
             {
                 phPageContent.InnerHtml = b.Content;
                 header.InnerHtml = b.Header;
                 Page.Title = b.Header;
             }
         }
     }
     else
     {
         mvBlog.SetActiveView(vAll);
         using (DBDataContext db = new DBDataContext())
         {
             var b = from B in db.Blog
                      select B;
             lvBlog.DataSource = b;
             lvBlog.DataBind();
         }
     }
 }
Пример #20
0
    public void PageChanged(object sender, EventArgs e)
    {
        lblError.Text = "";
        using (DBDataContext db = new DBDataContext())
        {
            int i;
            if (int.TryParse(ddlPages.SelectedValue, out i))
            {
                if (i > 0)
                {
                    var p = (from P in db.Pages
                             where P.id == i
                             select P).FirstOrDefault();
                    if (p != null)
                    {
                        txtLinkText.Text = p.DisplayLinkTitle;
                        txtPageHeader.Text = p.Title;
                        fckEditor.Value = p.Content;
                        btnMakeAsDefault.Visible = true;
                        btnDelete.Visible = true;
                        btnDelete.CommandArgument = p.id.ToString();
                        if (p.LeftMenu.Count() != 0 || p.TopMenuItem.Count() != 0)
                        {
                            StringBuilder pts = new StringBuilder();
                            foreach (LeftMenu lm in p.LeftMenu.ToList())
                            {
                                pts.AppendFormat(" '{0}' слева,", lm.ItemName);
                            }

                            foreach (TopMenuItem tm in p.TopMenuItem.ToList())
                            {
                                pts.AppendFormat(" '{0}' сверху,", tm.Title);
                            }

                            string str = pts.Length > 0 ? pts.ToString().Substring(0, pts.Length - 1) : "";

                            btnDelete.ToolTip = string.Format("Удалить эту страницу (ВНИМАНИЕ! Удаление этой страницы повлечет за собой удаление следующих пунктов меню:{0})", str);
                        }
                        else
                            btnDelete.ToolTip = "Удалить эту страницу";
                    }
                    else
                    {
                        btnMakeAsDefault.Visible = false;
                        btnDelete.Visible = false;
                    }
                    return;
                }
                else
                {
                    btnMakeAsDefault.Visible = false;
                    btnDelete.Visible = false;
                }
            }
            txtLinkText.Text = "";
            txtPageHeader.Text = "";
            fckEditor.Value = "";
        }
    }
Пример #21
0
 protected void Page_Load(object sender, EventArgs e)
 {
     using (DBDataContext DB = new DBDataContext())
       {
     lvSizes.DataSource = (from C in DB.Sizes select C).ToArray();
     lvSizes.DataBind();
       }
 }
Пример #22
0
        public CONVENIADO getConveniado()
        {
            DBDataContext db =
                new DBDataContext();
            var sql = from c in db.CONVENIADOs
                        where SqlMethods.Like(c.TITULAR,"%Sid%")
                        select c;

            return (CONVENIADO)sql;
        }
Пример #23
0
 public static string UpdateCategoryName(int id, string newName)
 {
     using (DBDataContext db = new DBDataContext())
     {
       Category cat = db.Categories.FirstOrDefault(C => C.ID == id);
       cat.Name = newName;
       db.SubmitChanges();
     }
     return newName;
 }
Пример #24
0
 protected void DeleteSize(object sender, EventArgs e)
 {
     int id = int.Parse(((Button)sender).CommandArgument);
     using (DBDataContext db = new DBDataContext())
     {
       Size size = db.Sizes.FirstOrDefault(S => S.ID == id);
       db.Sizes.DeleteOnSubmit(size);
       db.SubmitChanges();
     }
 }
Пример #25
0
        /// <summary>
        /// 返回数据库结果
        /// </summary>
        /// <returns></returns>
        public List<Item> GetResult()
        {
            DBDataContext ctx = new DBDataContext();

            var result = from l in ctx.Items
                         orderby l.CreatedTime descending
                         select l;

            return result.ToList();
        }
Пример #26
0
 public static void AddCategory(int parentID, string name)
 {
     using (DBDataContext db = new DBDataContext())
     {
       Category cat = new Category();
       cat.ParentCategory = parentID;
       cat.Name = name;
       db.Categories.InsertOnSubmit(cat);
       db.SubmitChanges();
     }
 }
Пример #27
0
 public static void UpdateVisibility(int id, bool visible)
 {
     using (DBDataContext db = new DBDataContext())
     {
       Item itm = db.Items.FirstOrDefault(I => I.ID == id);
       if (itm != null)
       {
     itm.Visible = visible;
     db.SubmitChanges();
       }
     }
 }
Пример #28
0
 public static void DeleteImage(int id)
 {
     using (DBDataContext db = new DBDataContext())
     {
       Pic pic = db.Pics.FirstOrDefault(P => P.ID == id);
       if (pic != null)
       {
     db.Pics.DeleteOnSubmit(pic);
     db.SubmitChanges();
       }
     }
 }
Пример #29
0
 protected void Page_LoadComplete(object sender, EventArgs e)
 {
     if (!IsPostBack)
     {
       mvSizes.SetActiveView(vAll);
     }
     using (DBDataContext db = new DBDataContext())
     {
       lvSizes.DataSource = db.Sizes;
       lvSizes.DataBind();
     }
 }
Пример #30
0
        public ActionResult DeleteFiles(string Id)
        {
            DBDataContext db = new DBDataContext();
            int IdCur = Convert.ToInt32(Id);
            fileContaner fd = db.fileContaner.FirstOrDefault(u => u.Id == IdCur);
            int? predmetId = fd.predmetId;
            db.ExecuteCommand("DELETE FROM Files WHERE Id=" + fd.docsId.ToString());
            db.ExecuteCommand("DELETE FROM Files WHERE Id=" + fd.programId.ToString());
            db.ExecuteCommand("DELETE FROM Files WHERE Id=" + fd.scanId.ToString());

            db.ExecuteCommand("DELETE FROM fileContaner WHERE Id=" + Id);
            return RedirectToAction("Downloads", new { id = predmetId });
        }