示例#1
0
        public void AddTest_Test()
        {
            context.SaveChanges().Returns(1);
            var result = adminService.AddTest(test.First(), question.ToList());

            Assert.That(result);
        }
示例#2
0
        /// <summary>
        /// Created By: Mayuresh kakade
        /// Date: 25/10/2018
        /// </summary>
        /// <returns>Register new user into user table</returns>
        public bool RegisterUser(user newUser)
        {
            try
            {
                user u = context.users.FirstOrDefault(x => x.username == newUser.username);

                if (u == null)
                {
                    MD5CryptoServiceProvider md5 = new MD5CryptoServiceProvider();
                    var verifyPassword           = md5.ComputeHash(ASCIIEncoding.ASCII.GetBytes(newUser.passw));
                    newUser.passw  = BitConverter.ToString(verifyPassword).Substring(0, 15);
                    newUser.roleID = 1;
                    newUser.userID = context.users.Count() + 1;
                    context.users.Add(newUser);
                    return(context.SaveChanges() > 0);
                }
                else
                {
                    return(false);
                }
            }
            catch (SqlException e)
            {
                throw;
            }
        }
示例#3
0
        public int AddCategory(category category)
        {
            try
            {
                int id = context.categories.Count() + 1;
                category.categoryID = id;
                category.created_on = DateTime.Now;
                int             result       = 0;
                int             flag         = 0;
                List <category> categoryList = context.categories.ToList();

                foreach (var item in categoryList)
                {
                    if (item.categoryName == category.categoryName)
                    {
                        flag = 1;
                        return(result);
                    }
                }
                if (flag == 0)
                {
                    context.categories.Add(category);
                    result = context.SaveChanges();
                }


                return(result);
            }
            catch (SqlException)
            {
                throw;
            }
            catch (Exception)
            {
                throw;
            }
        }