public JsonResult DeleteBike(int id)
        {
            if (ContextManager.Current.UserKey == null)
                return Json(new { Success = true, LoggedIn = false });
            else
            {
                var context = new DAL.DataClassesDataContext();
                var item = context.items.Where(i => i.id == id && i.user_key == ContextManager.Current.UserKey).SingleOrDefault();

                context.items.DeleteOnSubmit(item);
                context.SubmitChanges();

                HttpContext.Application["totalNumberOfBikesRegistered"] = Convert.ToInt32(HttpContext.Application["totalNumberOfBikesRegistered"]) - 1;

                return Json(new { Success = true, LoggedIn = true });
            }
        }
Пример #2
0
        public int saleItem(saleBO sale)
        {
            DataClassesDataContext data;
            string constr = @"Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename=D:\BCS DATA\Samester 6\C Sharp\Assingment 1\DAL\styloDatabase.mdf;Integrated Security=True";

            using (data = new DataClassesDataContext(constr))
            {
                var check = from a in data.Items
                            where a.PID == sale.Pid
                            select a;
                if (!check.Any())
                {
                    return(3);
                }
                else
                {
                    foreach (var s in check)
                    {
                        s.Quantity = 0;
                    }
                }
                Sale newItem = new Sale
                {
                    PID       = sale.Pid,
                    Sale_Date = sale.PurchaseDate
                };

                data.Sales.InsertOnSubmit(newItem);
                try
                {
                    data.SubmitChanges();
                    return(0);
                }
                catch (Exception e)
                {
                    return(1);
                }
            }
        }
Пример #3
0
        public int addItem(ItemBO item)
        {
            string constr = @"Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename=D:\BCS DATA\Samester 6\C Sharp\Assingment 1\DAL\styloDatabase.mdf;Integrated Security=True";

            using (DataClassesDataContext data = new DataClassesDataContext(constr))
            {
                var check = from a in data.Items
                            where a.PID == item.Pid
                            select a;
                if (check.Any())
                {
                    return(3);
                }
                Item newItem = new Item
                {
                    PID      = item.Pid,
                    Price    = item.Price,
                    Category = item.Category,
                    Size     = item.Size,
                    Color    = item.Color,
                    Brand    = item.Brand,
                    Date     = item.Date,
                    Quantity = 1
                };

                data.Items.InsertOnSubmit(newItem);
                try
                {
                    data.SubmitChanges();
                    return(0);
                }
                catch (Exception e)
                {
                    return(1);
                }
            }
        }
Пример #4
0
        public int registerUser(UserBO ub)
        {
            string constr = @"Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename=D:\BCS DATA\Samester 6\C Sharp\Assingment 1\DAL\styloDatabase.mdf;Integrated Security=True";

            using (DataClassesDataContext data = new DataClassesDataContext(constr))
            {
                var check = from a in data.Users
                            where a.Username == ub.Username
                            select a;


                if (check.Any())
                {
                    return(3);
                }



                User newUser = new User
                {
                    Username = ub.Username,
                    Password = ub.Password,
                    Role     = ub.Role
                };

                data.Users.InsertOnSubmit(newUser);
                try
                {
                    data.SubmitChanges();
                    return(0);
                }
                catch (Exception e)
                {
                    return(1);
                }
            }
        }
        public JsonResult StoreBike(item item)
        {
            if (ContextManager.Current.UserKey == null)
                return Json(new { Success = true, LoggedIn = false });
            else
            {
                var context = new DAL.DataClassesDataContext();
                //var item = new DAL.DataClassesDataContext().items.Where(i => i.serial_no == serialNo).SingleOrDefault();
                item.user_key = ContextManager.Current.UserKey;
                context.items.InsertOnSubmit(item);
                context.SubmitChanges();

                HttpContext.Application["totalNumberOfBikesRegistered"] = Convert.ToInt32(HttpContext.Application["totalNumberOfBikesRegistered"]) + 1;

                return Json(new { Success = true, LoggedIn = true });
            }
        }