Exemple #1
0
        public IActionResult Duyet(int maHD)
        {
            bool check         = true;
            var  chiTietHoaDon = _mb.ChiTietHoaDon.Where(ct => ct.MaHD == maHD).ToList();

            if (ModelState.IsValid)
            {
                string location = "";
                foreach (var chiTiet in chiTietHoaDon)
                {
                    for (int i = 0; i < chiTiet.SoLuong; i++)
                    {
                        location = chiTiet.MaDT.ToString() + i.ToString();
                        string IMEI = Request.Form[location];
                        if (_mb.IMEI_DienThoai.Where(im => im.IMEI == IMEI).SingleOrDefault() != null)
                        {
                            check = false;
                            TempData[location] = "Trùng IMEI vui lòng thử lại";
                        }
                        else
                        {
                            TempData[location] = IMEI;
                            _mb.SaveChangesAsync();
                        }
                    }
                }
                try
                {
                    if (!check)
                    {
                        throw new Exception();
                    }
                    foreach (var chiTiet in chiTietHoaDon)
                    {
                        for (int i = 0; i < chiTiet.SoLuong; i++)
                        {
                            location = chiTiet.MaDT.ToString() + i.ToString();
                            string         IMEI           = Request.Form[location];
                            IMEI_DienThoai iMEI_DienThoai = new IMEI_DienThoai()
                            {
                                IMEI = IMEI,
                                MaDT = chiTiet.MaDT,
                                MaHD = chiTiet.MaHD
                            };
                            _mb.Add(iMEI_DienThoai);
                        }
                    }
                    _mb.SaveChangesAsync();
                    return(RedirectToAction(nameof(Index)));
                }
                catch
                {
                    TempData["message"] = "Fail";
                    TempData.Keep();
                    TempData[location] = "Trùng IMEI vui lòng thử lại";
                    return(RedirectToAction("Duyet", new { maHD }));
                }
            }
            return(RedirectToAction("Duyet", new { maHD }));
        }
Exemple #2
0
        public async Task <IActionResult> Create(TaiKhoanAdmin taiKhoanAdmin)
        {
            if (ModelState.IsValid)
            {
                var checkUser  = _mb.TaiKhoanAdmin.Where(tk => tk.User == taiKhoanAdmin.User).SingleOrDefault();
                var CheckEmail = _mb.TaiKhoanAdmin.Where(tk => tk.Email == taiKhoanAdmin.Email).SingleOrDefault();
                if (checkUser != null)
                {
                    ModelState.AddModelError("", "User đã tồn tại vui lòng nhập lại!");
                    return(View(taiKhoanAdmin));
                }
                if (CheckEmail != null)
                {
                    if (Compare.CompareString(CheckEmail.Email, taiKhoanAdmin.Email))
                    {
                        ViewBag.khachHangAndDonHangs = News.SendName(_mb);
                        ModelState.AddModelError("", "Email đã tồn tại vui lòng nhập lại!");
                        return(View(taiKhoanAdmin));
                    }
                }
                taiKhoanAdmin.Pass = MD5.GetMD5(taiKhoanAdmin.Pass);
                _mb.Add(taiKhoanAdmin);
                await _mb.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewBag.khachHangAndDonHangs = News.SendName(_mb);
            return(View(taiKhoanAdmin));
        }
        public IActionResult Order(int phone_id, string user, string address, string phone)
        {
            var result = new object();

            if (phone_id != 0 && phone != null)
            {
                Order order = new Order()
                {
                    PhoneId      = phone_id,
                    User         = user,
                    Address      = address,
                    ContactPhone = phone,
                    DateTime     = DateTime.Now
                };
                _context.Add(order);
                _context.SaveChanges();
                result = new { message = "success" };
            }
            else
            {
                result = new { message = "error" };
            }

            return(Ok(result));
        }
Exemple #4
0
        public Companies InsertCompanies(Companies companies, out string errorMessage)
        {
            try
            {
                errorMessage = string.Empty;

                using (MobileContext context = new MobileContext())
                {
                    var _code = context.Companies.Max(x => x.CompanyCode) ?? "0";

                    companies.CompanyCode = (Convert.ToInt32(_code) + 1).ToString();
                    companies.Active      = "Y";
                    companies.AddDate     = DateTime.Now;

                    context.Add(companies);
                    if (context.SaveChanges() > 0)
                    {
                        return(companies);
                    }

                    errorMessage = "failed to create client.";
                    return(null);
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        public async Task <IActionResult> Duyet(int maDH)
        {
            if (ModelState.IsValid)
            {
                var donHangFromMb = await _mb.DonHang.Include(dh => dh.KhachHang).Where(m => m.MaDH == maDH).FirstOrDefaultAsync();

                HoaDon hoaDon = new HoaDon()
                {
                    MaDH      = donHangFromMb.MaDH,
                    MaKH      = donHangFromMb.MaKH,
                    NgayLapHD = DateTime.Now,
                    TenKH     = donHangFromMb.KhachHang.TenKH,
                    SoDT      = donHangFromMb.KhachHang.SoDienThoai,
                    GioiTinh  = donHangFromMb.KhachHang.GioiTinh,
                    DiaChi    = donHangFromMb.KhachHang.DiaChi
                };

                _mb.Add(hoaDon);
                _mb.SaveChanges();
                var chiTiet = _mb.ChiTietDonHang.Where(ct => ct.MaDH == maDH).ToList();
                foreach (var chiTietDonHang in chiTiet)
                {
                    int soLuong = Convert.ToInt32(Request.Form[chiTietDonHang.MaDT.ToString()]);
                    if (soLuong != 0)
                    {
                        ChiTietHoaDon ct = new ChiTietHoaDon()
                        {
                            MaHD    = hoaDon.MaHD,
                            MaDT    = chiTietDonHang.MaDT,
                            SoLuong = soLuong,
                            TongGia = chiTietDonHang.TongGia / chiTietDonHang.SoLuong * soLuong,
                        };
                        _mb.Add(ct);
                    }
                    hoaDon.TongThanhToan = hoaDon.TongThanhToan + chiTietDonHang.TongGia / chiTietDonHang.SoLuong * soLuong;
                    _mb.Update(hoaDon);
                    _mb.SaveChanges();
                }
                ;

                return(RedirectToAction("Duyet", "HoaDons", new { hoaDon.MaHD }));
            }
            return(RedirectToAction(nameof(Index)));
        }
        public async Task <IActionResult> Create(Product product)
        {
            if (ModelState.IsValid)
            {
                _context.Add(product);
                await _context.SaveChangesAsync();

                return(await Connection("Create", product));
            }
            return(View(product));
        }
Exemple #7
0
        public async Task <IActionResult> Create([Bind("Id_student,Imie,Nazwisko,Ulica,Kod_pocztowy,Miejscowosc,Email,Password")] Student student)
        {
            if (ModelState.IsValid)
            {
                _context.Add(student);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(student));
        }
Exemple #8
0
        public async Task <IActionResult> Create([Bind("Vid,Vname,Vmobile")] Vender vender)
        {
            if (ModelState.IsValid)
            {
                _context.Add(vender);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(vender));
        }
Exemple #9
0
        public async Task <IActionResult> Create([Bind("Id,Login,Password")] User user)
        {
            if (ModelState.IsValid)
            {
                _context.Add(user);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(user));
        }
Exemple #10
0
        public async Task <IActionResult> Create([Bind("Id,Category,Name,Company,Price")] Phone phone)
        {
            if (ModelState.IsValid)
            {
                _context.Add(phone);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(phone));
        }
Exemple #11
0
        public async Task <IActionResult> Create(Hang hang)
        {
            if (ModelState.IsValid)
            {
                ViewBag.khachHangAndDonHangs = News.SendName(_mb);
                _mb.Add(hang);
                await _mb.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(hang));
        }
Exemple #12
0
        public async Task <IActionResult> Create([Bind("Id_oceny,Ocena,Ocena_slownie,Id_student")] Student_Oceny student_Oceny)
        {
            if (ModelState.IsValid)
            {
                _context.Add(student_Oceny);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["Id_student"] = new SelectList(_context.Students, "Id_student", "Id_student", student_Oceny.Id_student);
            return(View(student_Oceny));
        }
Exemple #13
0
        public async Task <IActionResult> Create([Bind("OrderId,User,Address,ContactPhone,PhoneId")] Order order)
        {
            if (ModelState.IsValid)
            {
                _context.Add(order);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["PhoneId"] = new SelectList(_context.Phones, "Id", "Id", order.PhoneId);
            return(View(order));
        }
        public async Task <IActionResult> Create([Bind("CustomerId,CustomerName,CustomerNo")] Customer customer)
        {
            customer.Date = DateTime.Now.Date;
            if (ModelState.IsValid)
            {
                _context.Add(customer);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(customer));
        }
Exemple #15
0
        public async Task <IActionResult> Create([Bind("CatagoryId,CatagoryName")] Catagory catagory)
        {
            catagory.Date = DateTime.Today.Date;
            if (ModelState.IsValid)
            {
                _context.Add(catagory);

                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(catagory));
        }
        public async Task <IActionResult> Create(Phone phone)
        {
            if (ModelState.IsValid)
            {
                phone.CurrentDate = DateTime.Now;
                phone.CreatedDate = DateTime.Now;

                _context.Add(phone);
                await _context.SaveChangesAsync();

                return(await Connection("Create", phone));
            }
            return(View(phone));
        }
Exemple #17
0
        public async Task <IActionResult> Create([Bind("Id,Name,Company,Price,ImageFile")] Phone phone)
        {
            if (ModelState.IsValid)
            {
                if (phone.ImageFile != null)
                {
                    string folderPath = Path.Combine(_webHostEnvironment.WebRootPath, "images", "phone_images");
                    string fileName   = $"{Guid.NewGuid().ToString()}_{phone.ImageFile.FileName}";
                    string filePath   = Path.Combine(folderPath, fileName);

                    using (var stream = new FileStream(filePath, FileMode.Create))
                    {
                        phone.ImageFile.CopyTo(stream);
                    }

                    phone.ImageName = fileName;
                }
                _context.Add(phone);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(phone));
        }
Exemple #18
0
        public async Task <IActionResult> Create([Bind("PurchaseId,VenderId,ItemsId,Pquanity,PricePerUnit,TotalPrice,Date")] Purchase purchase)
        {
            Items oitem = _context.Items.Where(abc => abc.ItemsId == Convert.ToInt32(purchase.ItemsId)).FirstOrDefault <Items>();
            int   a     = Convert.ToInt32(oitem.Quantity) + Convert.ToInt32(purchase.Pquanity);

            oitem.Quantity = a;
            _context.Items.Update(oitem);

            if (ModelState.IsValid)
            {
                _context.Add(purchase);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["ItemsId"]  = new SelectList(_context.Items, "ItemsId", "ItemsId", purchase.ItemsId);
            ViewData["VenderId"] = new SelectList(_context.Vender, "Vid", "Vid", purchase.VenderId);
            return(View(purchase));
        }
        public async Task <IActionResult> Create([Bind("SalesId,CustomerId,ItemsId,Quantity,PricePerUnit,TotalPrice,TrDate")] Sales sales)
        {
            Items oitem = _context.Items.Where(abc => abc.ItemsId == Convert.ToInt32(sales.ItemsId)).FirstOrDefault <Items>();
            int   a     = Convert.ToInt32(oitem.Quantity) - Convert.ToInt32(sales.Quantity);

            oitem.Quantity = a;
            sendMail(sales);
            _context.Items.Update(oitem);
            if (ModelState.IsValid)
            {
                _context.Add(sales);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["CustomerId"] = new SelectList(_context.Customer, "CustomerId", "CustomerId", sales.CustomerId);
            ViewData["ItemsId"]    = new SelectList(_context.Items, "ItemsId", "ItemsId", sales.ItemsId);
            return(View(sales));
        }
Exemple #20
0
        public async Task <IActionResult> New(FilmViewModel model)
        {
            if (ModelState.IsValid)
            {
                string uniqueFileName = UploadedFile(model);

                Film film = new Film
                {
                    Title       = model.Title,
                    Description = model.Description,
                    Year        = model.Year,
                    Director    = model.Director,
                    Poster      = uniqueFileName,
                };
                _context.Add(film);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View());
        }
Exemple #21
0
 public Visit  InsertVisit(string employeeCode, Visit visit, string visitType)
 {
     try
     {
         using (MobileContext context = new MobileContext())
         {
             visit.VisitType       = visitType;
             visit.VisitedEmployee = employeeCode;
             visit.AddDate         = DateTime.Now;
             context.Add(visit);
             if (context.SaveChanges() > 0)
             {
                 return(visit);
             }
         }
         return(null);
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
        public async Task <IActionResult> Create(TaiKhoanAdmin taiKhoanAdmin)
        {
            if (ModelState.IsValid)
            {
                if (_mb.TaiKhoanAdmin.Where(tk => tk.User == taiKhoanAdmin.User).SingleOrDefault() != null)
                {
                    ModelState.AddModelError("", "User đã tồn tại vui lòng nhập lại!");
                }
                else if (_mb.TaiKhoanAdmin.Where(tk => tk.Email.Equals(taiKhoanAdmin.Email)).SingleOrDefaultAsync() != null)
                {
                    ModelState.AddModelError("", "Email đã tồn tại vui lòng nhập lại!");
                }
                else
                {
                    taiKhoanAdmin.Pass = MD5.GetMD5(taiKhoanAdmin.Pass);
                    _mb.Add(taiKhoanAdmin);
                    await _mb.SaveChangesAsync();

                    return(RedirectToAction(nameof(Index)));
                }
            }
            ViewBag.khachHangAndDonHangs = News.SendName(_mb);
            return(View(taiKhoanAdmin));
        }
Exemple #23
0
        public async Task <IActionResult> Create([Bind("ItemsId,CatagoryId,CatagoryName,ItemsName,Description,Quantity,Price,Image,Model,Color")] Items items, ICollection <IFormFile> Image)
        {
            string wwwrootPath  = env.WebRootPath;
            string PPFolderPath = wwwrootPath + "/ItemsImage/";

            foreach (var file in Image)
            {
                string Name       = file.Name;
                string FileName   = file.FileName;
                long   FileLength = file.Length;

                string FileNameWithoutExtension = Path.GetFileNameWithoutExtension(FileName);
                Random r = new Random();

                FileNameWithoutExtension = DateTime.Now.ToString("ddMMyyyyhhmm") + r.Next(1, 1000).ToString();
                string Extension = Path.GetExtension(FileName);

                FileStream fs = new FileStream(PPFolderPath + FileNameWithoutExtension + Extension, FileMode.CreateNew);
                file.CopyTo(fs);
                fs.Close();
                fs.Dispose();


                items.Image = "~/ItemsImage/" + FileNameWithoutExtension + Extension;
            }

            if (ModelState.IsValid)
            {
                _context.Add(items);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }

            return(View(items));
        }
 public MobileItems AddMobileDL(MobileItems mobile)
 {
     _context.Add(mobile);
     _context.SaveChanges();
     return(mobile);
 }
        public async Task <IActionResult> EditOrCreate(string id)
        {
            bool check = true;

            if (ModelState.IsValid)
            {
                CTHoaDonViewIMEIVM.chiTietHoaDon = await _mb.ChiTietHoaDon.SingleOrDefaultAsync(ct => (ct.MaHD.ToString() + ct.MaDT.ToString()).Equals(id));

                CTHoaDonViewIMEIVM.iMEI_DienThoais = await _mb.IMEI_DienThoai.Where(ct => (ct.MaHD.ToString() + ct.MaDT.ToString()).Equals(id)).ToListAsync();

                foreach (var im in CTHoaDonViewIMEIVM.iMEI_DienThoais)
                {
                    _mb.Attach(im);
                    _mb.Remove(im);
                }
                string location = "";
                for (int i = 0; i < CTHoaDonViewIMEIVM.chiTietHoaDon.SoLuong; i++)
                {
                    location = CTHoaDonViewIMEIVM.chiTietHoaDon.MaDT.ToString() + i.ToString();
                    string IMEI = Request.Form[location];

                    if (_mb.IMEI_DienThoai.Where(im => (im.IMEI == IMEI) && !(im.MaHD.ToString() + im.MaDT.ToString()).Equals(id)).SingleOrDefault() != null)
                    {
                        check = false;
                        TempData[location] = "Trùng IMEI vui lòng thử lại";
                    }
                    else
                    {
                        TempData[location] = IMEI;
                    }
                }

                try
                {
                    if (!check)
                    {
                        throw new Exception();
                    }
                    for (int i = 0; i < CTHoaDonViewIMEIVM.chiTietHoaDon.SoLuong; i++)
                    {
                        location = CTHoaDonViewIMEIVM.chiTietHoaDon.MaDT.ToString() + i.ToString();
                        string IMEI = Request.Form[location];



                        IMEI_DienThoai iMEI_DienThoai = new IMEI_DienThoai()
                        {
                            IMEI = IMEI,
                            MaDT = CTHoaDonViewIMEIVM.chiTietHoaDon.MaDT,
                            MaHD = CTHoaDonViewIMEIVM.chiTietHoaDon.MaHD
                        };
                        _mb.Add(iMEI_DienThoai);
                    }
                    await _mb.SaveChangesAsync();

                    return(RedirectToAction(nameof(Index)));
                }
                catch
                {
                    TempData["message"] = "Fail";
                    TempData[location]  = "Trùng IMEI vui lòng thử lại";
                    return(RedirectToAction("Edit", new { id }));
                }
            }
            return(RedirectToAction("Edit", new { id }));
        }