Esempio n. 1
0
        public async Task <long> AddAsync(Country country)
        {
            _dbContext.Add(country);
            await _dbContext.SaveChangesAsync();

            return(country.CountryId);
        }
Esempio n. 2
0
        public IHttpResponse RegisterConfirm(IHttpRequest httpRequest)
        {
            using (var context = new DemoDbContext())
            {
                string username        = httpRequest.FormData["username"].ToString();
                string password        = httpRequest.FormData["password"].ToString();
                string confurmPassword = httpRequest.FormData["confirmPassword"].ToString();

                if (password != confurmPassword)
                {
                    return(this.Redirect("/registet"));
                }

                User user = new User
                {
                    Username = username,
                    Password = password
                };

                context.Add(user);
                context.SaveChanges();
            }

            return(this.Redirect("/users/login"));
        }
 public async Task<IActionResult> Create([Bind("Id,Name,LastName")] Student student)
 {
     if (ModelState.IsValid)
     {
         _context.Add(student);
         await _context.SaveChangesAsync();
         return RedirectToAction(nameof(Index));
     }
     return View(student);
 }
        public IActionResult Create(Person person, Address address, Church church, Contact contact, PersonName personName)
        {
            _context.Add(person);
            address.Person    = person;
            church.Person     = person;
            contact.Person    = person;
            personName.Person = person;


            _context.Add(address);
            _context.Add(church);
            _context.Add(contact);
            _context.Add(personName);

            _context.SaveChanges();



            return(RedirectToAction("Index"));
        }
Esempio n. 5
0
        public async Task <IActionResult> OnPost()
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }
            _context.Add(Book);
            await _context.SaveChangesAsync();

            Message = "Book has been created successful";
            return(RedirectToPage("Index"));
        }
Esempio n. 6
0
        static void InitData(string dbName, string prjId)
        {
            DemoDbContext context = new DemoDbContext(AdoHelper.CreateHelper(dbName));
            //分类ID

            int delId = 0;

            for (int i = 0; i < 100; i++)
            {
                TestEntity test = new TestEntity();
                test.Name           = "Name" + i;
                test.AtTime         = DateTime.Now;
                test.Classification = prjId;
                context.Add(test);

                UserEntity user = new UserEntity();
                user.Name     = "User" + i;
                user.Sex      = false;
                user.Height   = 1.6f + i / 10;
                user.Birthday = new DateTime(1990, 1, 1).AddDays(i);
                context.Add(user);

                if (i == 50)
                {
                    delId = test.ID;
                }
            }
            //删除数据,确保被删除的ID写入到ID删除记录表中
            using (IWriteDataWarpper warpper = WriteDataWarpperFactory.Create(context))
            {
                context.Remove(new TestEntity()
                {
                    ID = delId
                });
                context.Remove(new UserEntity()
                {
                    UID = delId
                });
            }
        }
Esempio n. 7
0
        //添加动作
        public async Task <IActionResult> GoodsInfosCreates(int?ClassCode, string GoodsInfoName, string GoodsInfoPrice, string GoodsInfoImageUrl)
        {
            var Aid = HttpContext.Session.GetString("Aid");

            if (Aid == null)
            {
                return(RedirectToAction("Login", "Login"));
            }
            if (ClassCode == null || GoodsInfoName == null || GoodsInfoPrice == null || GoodsInfoImageUrl == null)
            {
                return(Content("404"));
            }
            if (_context.GoodsInfo.Where(a => a.GoodsInfoName == GoodsInfoName).Count() == 0 || _context.GoodsInfo.Where(a => a.GoodsInfoImageUrl == GoodsInfoImageUrl).Count() == 0)
            {
                try
                {
                    var GoodsInfo = new GoodsInfo
                    {
                        GoodsInfoName           = GoodsInfoName,
                        GoodsInfoPrice          = GoodsInfoPrice,
                        GoodsInfoImageUrl       = GoodsInfoImageUrl,
                        GoodsClassificationCode = Convert.ToInt32(ClassCode),
                    };
                    _context.Add(GoodsInfo);
                    await _context.SaveChangesAsync();

                    return(Content("200"));
                }
                catch (DbUpdateConcurrencyException)
                {
                    return(Content("500"));
                }
            }
            else
            {
                return(Content("201"));
            }
        }
Esempio n. 8
0
        //添加动作
        public async Task <IActionResult> AdminUsersCreates(AdminUserSexes AdminUserSex, AdminUserRoleType RoleType, string AdminUserName, string AdminUserNumber, string AdminUserPhoneNumber, string AdminUserPwd)
        {
            var Aid = HttpContext.Session.GetString("Aid");

            if (Aid == null)
            {
                return(RedirectToAction("Login", "Login"));
            }
            if (RoleType.ToString() == "" || AdminUserName == "" || AdminUserNumber == "" || AdminUserPwd == "")
            {
                return(Content("400"));
            }
            if (_context.AdminUser.Where(a => a.AdminUserNumber == AdminUserNumber).Count() == 0 || _context.AdminUser.Where(a => a.AdminUserName == AdminUserName).Count() == 0 || _context.AdminUser.Where(a => a.AdminUserPhoneNumber == AdminUserPhoneNumber).Count() == 0)
            {
                string AdminUserMD5Pwd = "";
                MD5    md5             = MD5.Create();
                byte[] s = md5.ComputeHash(Encoding.UTF8.GetBytes(AdminUserPwd));
                for (int i = 0; i < s.Length; i++)
                {
                    AdminUserMD5Pwd = AdminUserMD5Pwd + s[i].ToString("X");
                }
                try
                {
                    var AdminUser = new AdminUser
                    {
                        AdminUserCode        = AdminUserNumber + (int)RoleType,
                        AdminUserName        = AdminUserName,
                        AdminUserNumber      = AdminUserNumber,
                        AdminUserPwd         = AdminUserMD5Pwd,
                        RoleType             = RoleType,
                        AdminUserSex         = AdminUserSex,
                        AdminUserPhoneNumber = AdminUserPhoneNumber
                    };
                    _context.Add(AdminUser);
                    await _context.SaveChangesAsync();

                    return(Content("200"));
                }
                catch (DbUpdateConcurrencyException)
                {
                    return(Content("500"));
                }
            }
            else
            {
                return(Content("201"));
            }
        }
Esempio n. 9
0
        public async Task <CustomerModel> SubmitCustomer([FromBody] CustomerModel model)
        {
            Customer customer = new Customer
            {
                Id          = 0,
                FullName    = model.FullName,
                PhoneNumber = model.PhoneNumber
            };

            Log.Information($"Novi primatelj. Ime: {model.FullName}; Telefon: {model.PhoneNumber}");


            demoDbContext.Add <Customer>(customer);
            await demoDbContext.SaveChangesAsync();

            return(customer.GetViewModel());
        }
Esempio n. 10
0
        //添加动作
        public async Task <IActionResult> RotationImagesCreates(string RotationImagesUrl, string RotationImagesJumpUrl)
        {
            var Aid = HttpContext.Session.GetString("Aid");

            if (Aid == null)
            {
                return(RedirectToAction("Login", "Login"));
            }

            if (RotationImagesUrl != null)
            {
                if (_context.RotationImage.Where(a => a.RotationImageUrl == RotationImagesUrl).Count() == 0)
                {
                    if (_context.RotationImage.Where(a => a.RotationImageJumpUrl == RotationImagesJumpUrl).Count() == 0)
                    {
                        try
                        {
                            var rotationImage = new RotationImage
                            {
                                RotationImageUrl     = RotationImagesUrl,
                                RotationImageJumpUrl = RotationImagesJumpUrl,
                            };
                            _context.Add(rotationImage);
                            await _context.SaveChangesAsync();

                            return(Content("200"));
                        }
                        catch (DbUpdateConcurrencyException)
                        {
                            return(Content("404"));
                        }
                    }
                    else
                    {
                        return(Content("201"));
                    }
                }
                else
                {
                    return(Content("201"));
                }
            }
            return(Content("500"));
        }
        public async Task <IActionResult> Create([Bind("Id,Item,Amount")] Payment payment)
        {
            if (ModelState.IsValid)
            {
                // Custom timing for MiniProfiler
                using (CustomTiming timing = MiniProfiler.Current.CustomTiming("MyLongRun", "Test command", executeType: "Test", includeStackTrace: true))
                {
                    payment.Id       = Guid.NewGuid();
                    payment.CreateOn = DateTimeOffset.UtcNow;
                    _dbcontext.Add(payment);
                    await _dbcontext.SaveChangesAsync();

                    timing.CommandString = $"Inserting {payment.Item} with amount {payment.Amount.ToString()}.";
                }

                return(RedirectToAction(nameof(Index)));
            }
            return(View(payment));
        }
Esempio n. 12
0
        public async Task <IActionResult> AddOrUpdate(ProductViewModel productVM)
        {
            if (ModelState.IsValid)
            {
                if (productVM.Id == 0)
                {
                    dbContext.Add(productVM);
                }
                else
                {
                    dbContext.Update(productVM);
                }

                await dbContext.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }
            else
            {
                return(View(productVM));
            }
        }