protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack &&
                    !HttpContext.Current.User.Identity.IsAuthenticated)
            {
                Response.RedirectToRoute("login");
                return;
            }

            if (Security.Authorizate(HttpContext.Current.User.Identity.Name) == Security.SystemRoles.User)
            {
                Response.RedirectToRoute("login");
                return;
            }

            int sectionId;
            if (int.TryParse(Request.Form["remove"], out sectionId))
            {
                using (AuctionEntities au = new AuctionEntities())
                {
                    Section section = au.Sections
                        .First(s => s.Id == sectionId);

                    if (section != null && section.Id != 1)
                    {
                        au.Sections.Remove(section);
                        au.SaveChanges();

                    }
                }
            }
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack &&
               !HttpContext.Current.User.Identity.IsAuthenticated)
            {
                Response.RedirectToRoute("login");
                return;
            }

            if (!Page.IsPostBack
                && HttpContext.Current.User.Identity.IsAuthenticated)
            {
                using (AuctionEntities au = new AuctionEntities())
                {
                    User user = au.Users
                        .First(u => u.Login == HttpContext.Current.User.Identity.Name);

                    LoginInfo.Text = user.Login;
                    RoleInfo.Text = user.Role.NameRole;
                    NameInfo.Text = user.Name;
                    EmailInfo.Text = user.Email;
                    AddressInfo.Text = user.Address;
                    PhoneInfo.Text = user.Phone;

                    MyLotsInfo.Text = au.UserLots
                       .Count(ul => ul.IdUser == user.Id && ul.idStatus == 1).ToString();
                    SellLotsInfo.Text = au.UserLots
                        .Count(ul => ul.IdUser == user.Id && ul.idStatus == 4).ToString();
                    BuyLotsInfo.Text = au.UserLots
                        .Count(ul => ul.IdUser == user.Id && ul.idStatus == 5).ToString();
                }

            }
        }
 protected void EmailCheckValidator_ServerValidate(object source, ServerValidateEventArgs args)
 {
     using (AuctionEntities au = new AuctionEntities())
     {
         args.IsValid = !(au.Users
            .Any(u => u.Email == emailBox.Text));
     }
 }
 protected void nameCheckValidator_ServerValidate(object source, ServerValidateEventArgs args)
 {
     using (AuctionEntities au = new AuctionEntities())
     {
         args.IsValid = !(au.Sections
            .Any(s => s.NameSection == nameBox.Text));
     }
 }
 protected void UserExistValidator_ServerValidate(object source,
     ServerValidateEventArgs args)
 {
     using (AuctionEntities au = new AuctionEntities())
     {
         args.IsValid = !(au.Users
             .Any(u => u.Login == loginBox.Text));
     }
 }
Beispiel #6
0
 public static bool Authenticate(string login, string password)
 {
     using (AuctionEntities au = new AuctionEntities())
     {
         return au.Users
         .Any(u => u.Login == login
         && u.Password == password);
     }
 }
Beispiel #7
0
 protected void PswValidator_ServerValidate(object source,
 ServerValidateEventArgs args)
 {
     using (AuctionEntities au = new AuctionEntities())
     {
         args.IsValid = (au.Users
             .Count(u => u.Login
                == HttpContext.Current.User.Identity.Name &&
                u.Password == oldPswBox.Text) == 1);
     }
 }
Beispiel #8
0
        public static SystemRoles Authorizate(string login)
        {
            using (AuctionEntities au = new AuctionEntities())
            {
                int role = au.Users
                .Where(u => u.Login == login)
                .Select(u => u.IdRole)
                .FirstOrDefault();

                return (SystemRoles)role;
            }
        }
        protected void RegButton_Click(object sender, EventArgs e)
        {
            Page.Validate();

            if (Page.IsValid)
            {
                using (AuctionEntities au = new AuctionEntities())
                {

                    User user = new User();
                    user.Login = loginBox.Text;
                    user.Password = passBox.Text;
                    user.Email = emailBox.Text;
                    user.IdRole = roleId;
                    Methods.AddUser(user);
                    RegMultiView.ActiveViewIndex = 1;
                }
            }
        }
Beispiel #10
0
        protected void PswSaveBtn_Click(object sender, EventArgs e)
        {
            Page.Validate();
            if (Page.IsValid)
            {
                using (AuctionEntities au = new AuctionEntities())
                {
                    User user = au.Users
                    .First(u => u.Login
                         == HttpContext.Current.User.Identity.Name);

                    if (user != null)
                    {
                        user.Password = newPswBox.Text;
                        Methods.AddUser(user);
                        ChangePswView.ActiveViewIndex = 1;
                    }
                }
            }
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack &&
             !HttpContext.Current.User.Identity.IsAuthenticated)
            {
                Response.RedirectToRoute("login");
                return;
            }
            if (!Page.IsPostBack &&
              HttpContext.Current.User.Identity.IsAuthenticated)
            {

                if (Security.Authorizate(HttpContext.Current.User.Identity.Name) == Security.SystemRoles.User)
                {
                    Response.RedirectToRoute("login");
                    return;
                }
                MultiView.ActiveViewIndex = 0;
                int sectionId;
                int.TryParse((string)Page.RouteData.Values["editsection"]
                                ?? Request.QueryString["editsection"], out sectionId);

                if (sectionId == 1)
                {
                    Response.RedirectToRoute("sectionmng");
                    return;
                }
                else
                {
                    if (sectionId != 0)
                    {
                        using (AuctionEntities au = new AuctionEntities())
                        {
                            section = au.Sections.First(s => s.Id == sectionId);
                            nameBox.Text = section.NameSection;
                        }
                    }
                }
            }
        }
Beispiel #12
0
        protected void saveBtn_Click(object sender, EventArgs e)
        {
            Page.Validate();
            if (Page.IsValid)
            {
                using (AuctionEntities au = new AuctionEntities())
                {
                    User user = au.Users
                    .First(u => u.Login
                         == HttpContext.Current.User.Identity.Name);

                    if (user != null)
                    {
                        user.Name = nameBox.Text;
                        user.Address = addressBox.Text;
                        user.Phone = phoneBox.Text;
                        Methods.AddUser(user);
                        MultiView.ActiveViewIndex = 1;

                    }
                }
            }
        }
Beispiel #13
0
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack &&
              !HttpContext.Current.User.Identity.IsAuthenticated)
            {
                Response.RedirectToRoute("login");
                return;
            }
            if (!Page.IsPostBack &&
              HttpContext.Current.User.Identity.IsAuthenticated)
            {
                MultiView.ActiveViewIndex = 0;
                using (AuctionEntities au = new AuctionEntities())
                {
                    User user = au.Users
                       .First(u => u.Login == HttpContext.Current.User.Identity.Name);

                    nameBox.Text = user.Name;
                    addressBox.Text = user.Address;
                    phoneBox.Text = user.Phone;
                }
            }
        }
Beispiel #14
0
        public static string RandomLotImg()
        {
            using (AuctionEntities au = new AuctionEntities())
            {
                int rnd = new Random().Next(au.Lots.Count());

                string imgTag = au.Lots
                    .OrderBy(l => l.IdLot)
                    .Skip(rnd)
                    .Select(l => l.Img)
                    .First();

                int lotId = au.Lots.Where(l => l.Img == imgTag)
                    .Select(l => l.IdLot)
                    .First();

                Lot lot = au.Lots.First(l => l.IdLot == lotId);

                string link = UrlCreater.CreateUrl(lot);
                string name = lot.Name;

                return imgTag + "*/*" + link + "*/*" + name;
            }
        }
Beispiel #15
0
        private void AddLot(Lot lot, DateTime date, AuctionEntities au)
        {
            Random rnd = new Random();
                lot.Name = nameBox.Text;
                lot.IdSection = au.Sections
                    .Where(s => s.NameSection == ddlSection.SelectedValue)
                    .Select(s => s.Id)
                    .First();
                lot.Description = descBox.Text;
                lot.Tick = Convert.ToDecimal(tickBox.Text);

                switch (ddlEndDate.SelectedIndex)
                {
                    case 0: lot.EndDate = date.AddHours(1); break;
                    case 1: lot.EndDate = date.AddDays(1); break;
                    case 2: lot.EndDate = date.AddDays(7); break;
                    case 3: lot.EndDate = date.AddMonths(1); break;
                }

                HttpPostedFile ps = Request.Files["filefield"];

                if ((ps != null) && (ps.ContentLength > 0))
                {

                    string fn = System.IO.Path.GetFileName(ps.FileName);
                    string fileName = rnd.Next(99999) + fn;
                    lot.Img = fileName;
                    string SaveLocation = Server.MapPath("~/DataBase/Images") + "\\" + fileName;
                    ps.SaveAs(SaveLocation);
                }

                Methods.AddLot(lot, au);
        }
        protected void saveBtn_Click(object sender, EventArgs e)
        {
            Page.Validate();

            if (Page.IsValid)
            {
                int sectionId;
                int.TryParse((string)Page.RouteData.Values["editsection"]
                                ?? Request.QueryString["editsection"], out sectionId);
                if (sectionId != 0)
                {
                    using (AuctionEntities au = new AuctionEntities())
                    {
                        section = au.Sections.First(s => s.Id == sectionId);
                        section.NameSection = nameBox.Text;
                        Methods.AddSection(section);
                        MultiView.ActiveViewIndex = 1;
                    }
                }
                else
                {
                    using (AuctionEntities au = new AuctionEntities())
                    {
                        Section newSection = new Section();
                        newSection.NameSection = nameBox.Text;
                        Methods.AddSection(newSection);
                        MultiView.ActiveViewIndex = 1;
                    }
                }
            }
        }
Beispiel #17
0
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack &&
                !HttpContext.Current.User.Identity.IsAuthenticated)
            {
                Response.RedirectToRoute("login");
                return;
            }
            if (!Page.IsPostBack &&
                  HttpContext.Current.User.Identity.IsAuthenticated)
            {
                MultiView.ActiveViewIndex = 0;
                int lotId;
                int.TryParse((string)Page.RouteData.Values["editlot"]
                                ?? Request.QueryString["editlot"], out lotId);
                if (lotId != 0)
                {
                    if (Security.Authorizate(HttpContext.Current.User.Identity.Name) == Security.SystemRoles.User)
                    {
                        using (AuctionEntities au = new AuctionEntities())
                        {
                            User user = au.Users
                               .First(u => u.Login == HttpContext.Current.User.Identity.Name);

                            if (!au.UserLots.Any(ul => ul.IdLot == lotId && ul.IdUser == user.Id && ul.idStatus == 1))
                            {
                                Response.RedirectToRoute("userlots");
                                return;
                            }
                        }
                    }
                    using (AuctionEntities au = new AuctionEntities())
                    {
                        lot = au.Lots.First(l => l.IdLot == lotId);
                        if (lot.Status == false)
                        {
                            Response.RedirectToRoute("lotsmng");
                        }
                        else
                        {

                            nameBox.Text = lot.Name;
                            ddlSection.SelectedValue = lot.Section.NameSection;
                            startDateBox.Text = lot.StartDate.ToString("dd.MM.yyyy, HH:mm");
                            TimeSpan dt = lot.EndDate - lot.StartDate;
                            switch (dt.Days)
                            {
                                case 1: ddlEndDate.SelectedIndex = 1; break;
                                case 7: ddlEndDate.SelectedIndex = 2; break;
                                case 30: ddlEndDate.SelectedIndex = 3; break;
                                default: ddlEndDate.SelectedIndex = 0; break;
                            }
                            startPriceBox.Enabled = false;
                            startPriceBox.Text = lot.StartPrice.ToString();
                            tickBox.Text = lot.Tick.ToString();
                            descBox.Text = lot.Description;
                        }
                    }

                }
                else
                {
                    startDateBox.Text = DateTime.Now.ToString("dd-MM-yyyy, HH:mm");
                }

            }
        }
Beispiel #18
0
        protected void saveBtn_Click(object sender, EventArgs e)
        {
            Page.Validate();

            if (Page.IsValid)
            {

                int lotId;
                int.TryParse((string)Page.RouteData.Values["editlot"]
                                ?? Request.QueryString["editlot"], out lotId);

                if (lotId !=0)
                {
                    using (AuctionEntities au = new AuctionEntities())
                    {
                        using (var tran = au.Database.BeginTransaction())
                        {
                            try
                            {
                                lot = au.Lots.First(l => l.IdLot == lotId);
                                AddLot(lot, lot.StartDate, au);
                                au.SaveChanges();
                                tran.Commit();
                                lblError.Text = "Лот успешно изменен!";
                                MultiView.ActiveViewIndex = 1;

                                Methods.UpdateLotsStatus();

                            }
                            catch (Exception)
                            {
                                tran.Rollback();
                            }
                        }
                    }
                }
                else
                {
                    HttpPostedFile ps = Request.Files["filefield"];
                    if ((ps != null) && (ps.ContentLength <= 0))
                    {
                        lblError.Text = "Изображение не выбрано!";
                        return;
                    }

                    using (AuctionEntities au = new AuctionEntities())
                    {
                        using (var tran = au.Database.BeginTransaction())
                        {
                            try
                            {
                                Lot newLot = new Lot();
                                newLot.StartDate = DateTime.Now;
                                newLot.StartPrice = Convert.ToDecimal(startPriceBox.Text);
                                newLot.CurrentPrice = Convert.ToDecimal(startPriceBox.Text);
                                newLot.Status = true;
                                AddLot(newLot, DateTime.Now, au);

                                int userId = au.Users
                                        .Where(u => u.Login == HttpContext.Current.User.Identity.Name)
                                        .Select(u => u.Id)
                                        .First();
                                UserLot userLot = new UserLot();
                                userLot.IdLot = newLot.IdLot;
                                userLot.IdUser = userId;
                                userLot.idStatus = 1;
                                Methods.AddUserLot(userLot, au);
                                au.SaveChanges();
                                tran.Commit();
                                lblError.Text = "Лот успешно добавлен!";
                                MultiView.ActiveViewIndex = 1;

                                Methods.UpdateLotsStatus();
                            }
                            catch (Exception)
                            {
                                tran.Rollback();
                            }
                        }
                    }
                }
            }
        }