Exemplo n.º 1
0
        public Boolean AddCart(Cart model)
        {
            var availableStock = db.Products.Where(x => x.Product_Id == model.Product_Id).FirstOrDefault();
            int StockInHand    = availableStock.Product_Quantity;

            if (StockInHand > model.Quantity)
            {
                var Authorize = db.carts.Where(x => x.Product_Id == model.Product_Id && x.userId == model.userId).FirstOrDefault();
                if (Authorize == null)
                {
                    db.carts.Add(model);
                    db.SaveChanges();
                    var    query  = db.carts.Where(x => x.Cart_Id == model.Cart_Id).FirstOrDefault();
                    var    query1 = db.Products.Where(p => p.Product_Id == model.Product_Id).FirstOrDefault();
                    double price  = query1.Product_Price;
                    query.Price = price;
                    query.Total = (query.Quantity * price);
                    db.SaveChanges();
                    return(true);
                }
                else
                {
                    Authorize.Quantity = Authorize.Quantity + model.Quantity;
                    Authorize.Total    = Authorize.Total + (model.Quantity * Authorize.Price);
                    db.SaveChanges();
                    return(true);
                }
            }
            else
            {
                return(false);
            }
        }
        public T Add(T entity)
        {
            var newEntity = _entities.Add(entity);

            _dbContext.SaveChanges();
            return(newEntity);
        }
Exemplo n.º 3
0
        public ActionResult Create([Bind(Include = "ID,FileNumber,Secret,Reminder,Title,FirstName,Surname,IdNumber,BirthDate,EmailAddress,ContactNumber,CellNumber,Address1,Address2,Address3,Address4,ConsultationFee,CurrentBalance")] Patient patient)
        {
            if (ModelState.IsValid)
            {
                db.Patients.Add(patient);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(patient));
        }
Exemplo n.º 4
0
        public bool UpdateUser(string userID, string pass, string cName, string phone, string tel, string gender, string birth)
        {
            try
            {
                // Query the database for the row to be updated.
                var query =
                    (from mem in _context.Member
                     where mem.Account == userID
                     select mem).ToList();

                // Execute the query, and change the column values
                // you want to change.
                foreach (Member mem in query)
                {
                    mem.Password = pass;
                    mem.Name     = cName;
                    mem.Phone    = phone;
                    mem.Tel      = tel;
                    mem.Gender   = gender;
                    mem.Birthday = DateTime.Parse(birth);
                }


                _context.SaveChanges();

                return(true);
            }
            catch (DbEntityValidationException ex)
            {
                var entityError = ex.EntityValidationErrors.SelectMany(x => x.ValidationErrors).Select(x => x.ErrorMessage);

                return(false);
            }
        }
Exemplo n.º 5
0
        public int AddConsumer([FromBody] Consumer consumer)
        {
            try
            {
                _context.Consumer.Add(consumer);
                int numberEntriesSaved = _context.SaveChanges();
                return(numberEntriesSaved);
            }
            catch
            {
                throw;
            }

            //if (ModelState.IsValid)
            //    _dataLayer.AddConsumer(consumer);
        }
Exemplo n.º 6
0
        public static void OrderMock(PracticeContext context)
        {
            if (context.Order.Any())
            {
                return;
            }

            context.Order.AddRange(Enumerable.Range(1, 5).Select(c => CreateOrder(c, context)));
            context.SaveChanges();
        }
Exemplo n.º 7
0
        public bool AddCart(Cart model)
        {
            var availableStock = db.Products.Where(x => x.PId == model.PId).FirstOrDefault();
            int StockInHand    = model.Quantity;

            if (StockInHand >= model.Quantity)
            {
                var Authorize = db.Carts.Where(x => x.PId == model.PId && x.UId == model.UId).FirstOrDefault();
                if (Authorize == null)
                {
                    Product product = db.Products.Find(model.PId);
                    int     total   = product.Quantity * product.PPrice;
                    Cart    cart    = new Cart();
                    cart.PId         = model.PId;
                    cart.Item        = product.PImage;
                    cart.Description = product.PName;
                    cart.Quantity    = product.Quantity;
                    cart.Price       = product.PPrice;
                    cart.UId         = model.UId;
                    cart.Total       = total;
                    db.Carts.Add(cart);
                    db.SaveChanges();
                    return(true);
                }
                else
                {
                    db.Carts.Add(model);
                    db.SaveChanges();
                    Authorize.Quantity = Authorize.Quantity + model.Quantity;
                    Authorize.Total    = Authorize.Total + (model.Quantity * Authorize.Price);
                    db.SaveChanges();
                    return(true);
                }
            }
            else
            {
                return(false);
            }
        }
Exemplo n.º 8
0
        public static void CreateUser(PracticeContext context)
        {
            var user = new User()
            {
                Username      = "******",
                Password      = "",
                SecurityToken = "",
                Name          = "Ball",
                CreateDate    = DateTime.Now,
                UpdateDate    = DateTime.Now
            };

            context.Add(user);
            context.SaveChanges();
        }
Exemplo n.º 9
0
        public IActionResult Create(User NewUser)
        {
            User newUser = new User {
                FirstName = NewUser.FirstName,
                LastName  = NewUser.LastName,
                Email     = NewUser.Email,
                Password  = NewUser.Password
            };

            // We can take the User object created from a form submission
            // And pass this object to the .Add() method
            dbContext.Add(newUser);
            // OR dbContext.Users.Add(newUser);
            dbContext.SaveChanges();
            // Other code
            return(RedirectToAction("Index"));
        }
Exemplo n.º 10
0
        public static void SupplierMock(PracticeContext context)
        {
            if (context.Suppliers.Any())
            {
                return;
            }

            context.Suppliers.AddRange(Enumerable.Range(1, 5).Select(c => new Supplier
            {
                Name       = "Supplier_" + c,
                Address    = "Thailand",
                PhoneNo    = "084-874" + c,
                CreateDate = DateTime.Now,
                UpdateDate = DateTime.Now
            }));

            context.SaveChanges();
        }
Exemplo n.º 11
0
        public static void ActionStateMock(PracticeContext context)
        {
            if (context.ActionStates.Any())
            {
                return;
            }

            var user = context.Users.FirstOrDefault();

            var action = new ActionState()
            {
                By = user.Id,
                On = DateTime.Now.Ticks
            };

            context.ActionStates.Add(action);
            context.SaveChanges();
        }
Exemplo n.º 12
0
        public static void ItemsStateMock(PracticeContext context)
        {
            if (context.ItemStates.Any())
            {
                return;
            }

            var item = context.Items.ToArray().Select(c => new ItemState
            {
                ItemId        = c.Id,
                Type          = StateType.Get,
                ActionStateId = context.ActionStates.Select(x => x.Id).FirstOrDefault(),
                CreateDate    = DateTime.Now,
                UpdateDate    = DateTime.Now
            });

            context.ItemStates.AddRange(item);
            context.SaveChanges();
        }
Exemplo n.º 13
0
        public static void OrdersStateMock(PracticeContext context)
        {
            if (context.OrderStates.Any())
            {
                return;
            }

            var order = context.Order.ToArray().Select(c => new OrderState
            {
                OrderId       = c.Id,
                Type          = StateType.Get,
                ActionStateId = context.ActionStates.Select(x => x.Id).FirstOrDefault(),
                CreateDate    = DateTime.Now,
                UpdateDate    = DateTime.Now
            });

            context.OrderStates.AddRange(order);
            context.SaveChanges();
        }
Exemplo n.º 14
0
        private static void AddTopics(PracticeContext context)
        {
            var topicList = new List <Topic>
            {
                new Topic {
                    TopicId = "TAdd", TopicDesc = "Addition"
                },
                new Topic {
                    TopicId = "TSub", TopicDesc = "Subtraction"
                },
                new Topic {
                    TopicId = "TMul", TopicDesc = "Multiplication"
                },
                new Topic {
                    TopicId = "TDiv", TopicDesc = "Division"
                },
                new Topic {
                    TopicId = "TAlg", TopicDesc = "Algebra"
                },

                new Topic {
                    TopicId = "TDec", TopicDesc = "Decimal"
                },
                new Topic {
                    TopicId = "TFra", TopicDesc = "Fraction"
                },


                new Topic {
                    TopicId = "TNum", TopicDesc = "Number Sense"
                },
                new Topic  {
                    TopicId = "TInt", TopicDesc = "Integers"
                },
            };

            topicList.ForEach(s => context.Topics.Add(s));
            context.SaveChanges();
            Console.WriteLine("updated topics");
        }
        public void UpdateContext(PracticeContext context)
        {
            //Membership.CreateUser(“testuser”, “test123″);
            //Roles.CreateRole(“Administrator”);
            //Roles.AddUsersToRole(new[] {“testuser”}, “Administrator”);

            var topicList = new List <Topic>
            {
                new Topic {
                    TopicId = "TAdd", TopicDesc = "Adddition"
                },
                new Topic {
                    TopicId = "TSub", TopicDesc = "Subtraction"
                },
                new Topic {
                    TopicId = "TMul", TopicDesc = "Multipication"
                },
                new Topic {
                    TopicId = "TDiv", TopicDesc = "Division"
                },

                new Topic {
                    TopicId = "TAlg", TopicDesc = "Algebra"
                },
                new Topic {
                    TopicId = "TCom", TopicDesc = "Compare"
                },

                new Topic {
                    TopicId = "TFra", TopicDesc = "Fraction"
                },
                new Topic {
                    TopicId = "TDec", TopicDesc = "Decimal"
                },
                new Topic {
                    TopicId = "TPAl", TopicDesc = "Pre-Algebra"
                },
                new Topic {
                    TopicId = "TWor", TopicDesc = "WordProblem"
                },
            };

            topicList.ForEach(s => context.Topics.Add(s));
            context.SaveChanges();

            var subTopicList = new List <SubTopic>
            {
                //Add
                new SubTopic {
                    SubTopicId = "1001", SubTopicDesc = "Additions 1 to 9", TopicId = "TAdd"
                },
                new SubTopic {
                    SubTopicId = "1002", SubTopicDesc = "Additions 1 to 100", TopicId = "TAdd"
                },

                new SubTopic {
                    SubTopicId = "1003", SubTopicDesc = "Two Digit Additions 11-20 with 11-20", TopicId = "TAdd"
                },
                new SubTopic {
                    SubTopicId = "1004", SubTopicDesc = "Two Digit Additions with Regrouping", TopicId = "TAdd"
                },

                //Sub
                new SubTopic {
                    SubTopicId = "1101", SubTopicDesc = "Subtraction 1 to 9", TopicId = "TSub"
                },
                new SubTopic {
                    SubTopicId = "1102", SubTopicDesc = "Subtraction 1 to 100", TopicId = "TSub"
                },

                new SubTopic {
                    SubTopicId = "1103", SubTopicDesc = "Two Digit Subtraction 11-20 with 11-20", TopicId = "TSub"
                },
                new SubTopic {
                    SubTopicId = "1104", SubTopicDesc = "Two Digit Subtraction with Regrouping", TopicId = "TSub"
                },

                //Mul
                new SubTopic {
                    SubTopicId = "1201", SubTopicDesc = "Multiplication by 1", TopicId = "TMul"
                },
                new SubTopic {
                    SubTopicId = "1202", SubTopicDesc = "Multiplication by 2", TopicId = "TMul"
                },
                new SubTopic {
                    SubTopicId = "1203", SubTopicDesc = "Multiplication by 3", TopicId = "TMul"
                },
                new SubTopic {
                    SubTopicId = "1204", SubTopicDesc = "Multiplication by 4", TopicId = "TMul"
                },

                new SubTopic {
                    SubTopicId = "1205", SubTopicDesc = "Multiplication by 5", TopicId = "TMul"
                },
                new SubTopic {
                    SubTopicId = "1206", SubTopicDesc = "Multiplication by 6", TopicId = "TMul"
                },
                new SubTopic {
                    SubTopicId = "1207", SubTopicDesc = "Multiplication by 7", TopicId = "TMul"
                },
                new SubTopic {
                    SubTopicId = "1208", SubTopicDesc = "Multiplication by 8", TopicId = "TMul"
                },

                new SubTopic {
                    SubTopicId = "1209", SubTopicDesc = "Multiplication by 9", TopicId = "TMul"
                },
                new SubTopic {
                    SubTopicId = "1210", SubTopicDesc = "Multiplication by 10", TopicId = "TMul"
                },
                new SubTopic {
                    SubTopicId = "1211", SubTopicDesc = "Multiplication by 11", TopicId = "TMul"
                },
                new SubTopic {
                    SubTopicId = "1212", SubTopicDesc = "Multiplication by 12", TopicId = "TMul"
                },

                //new SubTopic {  SubTopicId="1213", SubTopicDesc ="Multiplication by 8", TopicId="TMul" },

                //Division
                new SubTopic {
                    SubTopicId = "1301", SubTopicDesc = "Division 1 to 9", TopicId = "TDiv"
                },
                new SubTopic {
                    SubTopicId = "1302", SubTopicDesc = "Division 1 to 100", TopicId = "TDiv"
                },

                new SubTopic {
                    SubTopicId = "1303", SubTopicDesc = "Two Digit Division 11-20 with 11-20", TopicId = "TDiv"
                },
                new SubTopic {
                    SubTopicId = "1304", SubTopicDesc = "Two Digit Division with Regrouping", TopicId = "TDiv"
                },

                //Algebra

                new SubTopic {
                    SubTopicId = "2001", SubTopicDesc = "Algebra for Addition", TopicId = "TAlg"
                },
                new SubTopic {
                    SubTopicId = "2101", SubTopicDesc = "Algebra for Subraction", TopicId = "TAlg"
                },

                new SubTopic {
                    SubTopicId = "2201", SubTopicDesc = "Algebra involving Mulitplication", TopicId = "TAlg"
                },
                new SubTopic {
                    SubTopicId = "2301", SubTopicDesc = "Algebra involving Division", TopicId = "TAlg"
                },
            };

            subTopicList.ForEach(s => context.SubTopics.Add(s));
            context.SaveChanges();

            //add the Grades Table
            // var gradeList = GradeList ?? SimpleInit.GetHardCodedGrades();
            var gradeList = new List <Grade>
            {
                //Add
                new Grade {
                    GradeId = "-1", GradeDesc = "Pre-K", GradeDesc2 = "PreSchool"
                },
                new Grade {
                    GradeId = "0", GradeDesc = "KinderGarten", GradeDesc2 = "KinderGarten"
                },
                new Grade {
                    GradeId = "1", GradeDesc = "Grade1", GradeDesc2 = "Grade1"
                },
                new Grade {
                    GradeId = "2", GradeDesc = "Grade2", GradeDesc2 = "Grade2"
                },
                new Grade {
                    GradeId = "3", GradeDesc = "Grade3", GradeDesc2 = "Grade3"
                },
                new Grade {
                    GradeId = "4", GradeDesc = "Grade4", GradeDesc2 = "Grade4"
                },
                new Grade {
                    GradeId = "5", GradeDesc = "Grade5", GradeDesc2 = "Grade5"
                },
                new Grade {
                    GradeId = "6", GradeDesc = "Grade6", GradeDesc2 = "Grade6"
                },
                new Grade {
                    GradeId = "7", GradeDesc = "Grade7", GradeDesc2 = "Grade7"
                },
                new Grade {
                    GradeId = "8", GradeDesc = "Grade8", GradeDesc2 = "Grade8"
                },
            };

            gradeList.ForEach(s => context.Grades.Add(s));
            context.SaveChanges();

            //var gradeSubTopicList = GradeSubTopicList ?? SimpleInit.GetHardCodedGrade_Subtopic();

            var gradeSubTopicList = new List <GradeSubTopic>
            {
                new GradeSubTopic {
                    GradeId = "-1", SubTopicId = "1001"
                },
                new GradeSubTopic {
                    GradeId = "-1", SubTopicId = "1002"
                },

                new GradeSubTopic {
                    GradeId = "0", SubTopicId = "1001"
                },
                new GradeSubTopic {
                    GradeId = "0", SubTopicId = "1002"
                },
                new GradeSubTopic {
                    GradeId = "0", SubTopicId = "1101"
                },
                new GradeSubTopic {
                    GradeId = "0", SubTopicId = "1102"
                },

                new GradeSubTopic {
                    GradeId = "1", SubTopicId = "1001"
                },
                new GradeSubTopic {
                    GradeId = "1", SubTopicId = "1002"
                },
                new GradeSubTopic {
                    GradeId = "1", SubTopicId = "1101"
                },
                new GradeSubTopic {
                    GradeId = "1", SubTopicId = "1102"
                },
                new GradeSubTopic {
                    GradeId = "1", SubTopicId = "1003"
                },
                new GradeSubTopic {
                    GradeId = "1", SubTopicId = "1004"
                },
                new GradeSubTopic {
                    GradeId = "1", SubTopicId = "1103"
                },
                new GradeSubTopic {
                    GradeId = "1", SubTopicId = "1104"
                },

                new GradeSubTopic {
                    GradeId = "2", SubTopicId = "1001"
                },
                new GradeSubTopic {
                    GradeId = "2", SubTopicId = "1002"
                },
                new GradeSubTopic {
                    GradeId = "2", SubTopicId = "1101"
                },
                new GradeSubTopic {
                    GradeId = "2", SubTopicId = "1102"
                },


                new GradeSubTopic {
                    GradeId = "3", SubTopicId = "1201"
                },
                new GradeSubTopic {
                    GradeId = "3", SubTopicId = "1202"
                },
                new GradeSubTopic {
                    GradeId = "3", SubTopicId = "1203"
                },
                new GradeSubTopic {
                    GradeId = "3", SubTopicId = "1204"
                },
                new GradeSubTopic {
                    GradeId = "3", SubTopicId = "1205"
                },
                new GradeSubTopic {
                    GradeId = "3", SubTopicId = "1206"
                },
                new GradeSubTopic {
                    GradeId = "3", SubTopicId = "1207"
                },
                new GradeSubTopic {
                    GradeId = "3", SubTopicId = "1208"
                },
                new GradeSubTopic {
                    GradeId = "3", SubTopicId = "1209"
                },
                new GradeSubTopic {
                    GradeId = "3", SubTopicId = "1210"
                },
                new GradeSubTopic {
                    GradeId = "3", SubTopicId = "1211"
                },
                new GradeSubTopic {
                    GradeId = "3", SubTopicId = "1212"
                },

                new GradeSubTopic {
                    GradeId = "4", SubTopicId = "1201"
                },
                new GradeSubTopic {
                    GradeId = "4", SubTopicId = "1202"
                },
                new GradeSubTopic {
                    GradeId = "4", SubTopicId = "1203"
                },
                new GradeSubTopic {
                    GradeId = "4", SubTopicId = "1204"
                },
                new GradeSubTopic {
                    GradeId = "4", SubTopicId = "1205"
                },

                new GradeSubTopic {
                    GradeId = "5", SubTopicId = "1201"
                },
                new GradeSubTopic {
                    GradeId = "5", SubTopicId = "1202"
                },
                new GradeSubTopic {
                    GradeId = "5", SubTopicId = "1203"
                },
                new GradeSubTopic {
                    GradeId = "5", SubTopicId = "1204"
                },
                new GradeSubTopic {
                    GradeId = "5", SubTopicId = "1205"
                },

                new GradeSubTopic {
                    GradeId = "6", SubTopicId = "1201"
                },
                new GradeSubTopic {
                    GradeId = "6", SubTopicId = "1202"
                },
                new GradeSubTopic {
                    GradeId = "6", SubTopicId = "1203"
                },
                new GradeSubTopic {
                    GradeId = "6", SubTopicId = "1204"
                },
                new GradeSubTopic {
                    GradeId = "6", SubTopicId = "1205"
                },

                new GradeSubTopic {
                    GradeId = "7", SubTopicId = "1201"
                },
                new GradeSubTopic {
                    GradeId = "7", SubTopicId = "1202"
                },
                new GradeSubTopic {
                    GradeId = "7", SubTopicId = "1203"
                },
                new GradeSubTopic {
                    GradeId = "7", SubTopicId = "1204"
                },
                new GradeSubTopic {
                    GradeId = "7", SubTopicId = "1205"
                },

                new GradeSubTopic {
                    GradeId = "8", SubTopicId = "1201"
                },
                new GradeSubTopic {
                    GradeId = "8", SubTopicId = "1202"
                },
                new GradeSubTopic {
                    GradeId = "8", SubTopicId = "1203"
                },
                new GradeSubTopic {
                    GradeId = "8", SubTopicId = "1204"
                },
                new GradeSubTopic {
                    GradeId = "8", SubTopicId = "1205"
                },
            };

            gradeSubTopicList.ForEach(s => context.GradeSubTopics.Add(s));
            context.SaveChanges();

            var questionList = QuestionList ?? SimpleInit.GetHardCodedQuestions();

            questionList.ForEach(s => context.Questions.Add(s));
            context.SaveChanges();

            var answerOptionsList = AnswerOptionList ?? SimpleInit.GetHardCodedAnsweOptions();

            answerOptionsList.ForEach(s => context.AnswerOptions.Add(s));
            context.SaveChanges();

            var questionDetailList = QuestionDetailList ?? SimpleInit.GetHardCodedQuestionDetails();

            questionDetailList.ForEach(s => context.QuestionDetails.Add(s));
            context.SaveChanges();

            //add the Sheet Tables
            var sheetList = SheetList ?? SimpleInit.GenerateSheetList();

            sheetList.ForEach(s => context.Sheet.Add(s));
            context.SaveChanges();

            //add the Question Sheet details
            var questionSheetList = QuestionSheetList ?? SimpleInit.GenerateQuestionSheetList();

            questionSheetList.ForEach(s => context.QuestionSheet.Add(s));
            context.SaveChanges();
        }
Exemplo n.º 16
0
 public IActionResult Post([FromBody] Game game)
 {
     _context.Games.Add(game);
     _context.SaveChanges();
     return(Created("", game));
 }