Exemple #1
0
        public async Task <IActionResult> Create([Bind("ID,name,phone,email,note,condition,cNumber,pNumber,ch,price,policy,charges,totals")] Customers customers)
        {
            if (ModelState.IsValid)
            {
                _context.Add(customers);
                customers.pDate = DateTime.Now.Date;
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(customers));
        }
Exemple #2
0
        public async Task <IActionResult> CreateContract([Bind("email,collabor,pDate,customer,phone,email,note,charge,condition,code")] Contracts contract)
        {
            _context.Add(contract);
            var customer = await _context.Customers.FirstOrDefaultAsync(c => c.phone == contract.phone);

            if (customer != null)
            {
                customer.signed = true;
            }

            await _context.SaveChangesAsync();

            //var contracts = await _context.Contracts.OrderBy(m => m.ID).ToListAsync();
            //var autho = _context.Administrator.First();
            return(RedirectToAction("Contract", "Administrator"));
        }
        public async Task <IActionResult> Collabor_Edit(int id, [Bind("policy,ID,email, fullName, password, office, joinDate, gender, birthday,cmnd,place, day, office_name,field, position, house, town, nation, city, district,zip, phone")] Collaborators collaborator)
        {
            if (id != collaborator.ID)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                _context.Update(collaborator);
                await _context.SaveChangesAsync();

                return(RedirectToAction("Collaborators"));
            }
            return(View(collaborator));
        }
        public async Task <IActionResult> CreateAppoinment([Bind("Customer,Gender,Address,Phone,Email,Job,WorkPlace,Cmnd,Day,Place,Money,Purpose,Requires,Price,Details,DType,Cash,NCH1,NCH2,NCH21,NCH3,NMS,NS,NSHH,NSH,HKTT,password,Contract,supporter")] Appoinment appoinment)
        {
            //if (ModelState.IsValid)
            //{
            var colls = await _context.Collaborators.ToListAsync();

            if (colls == null)
            {
                return(NotFound());
            }
            _colls = colls;
            foreach (Collaborators coll in colls)
            {
                if (coll.password == appoinment.password)
                {
                    TempData["name"]       = coll.fullName;
                    appoinment.sale        = coll.email;
                    appoinment.SaleDetails = coll.office;
                    break;
                }
            }
            string str = "";

            if (appoinment.sale == null)
            {
                return(View());
            }
            if (!Check(appoinment.sale, appoinment.password))
            {
                return(View());
            }
            else
            {
                //var recaptcha = await _recaptcha.Validate(Request);
                //if (!recaptcha.success)
                //{
                //    ModelState.AddModelError("Recaptcha", "There was an error validating recatpcha. Please try again!");
                //    return View();
                //}
                List <Appoinment> appoinments = await _context.appoinment.ToListAsync();

                if (appoinments.Count > 0)
                {
                    appoinment.Contract = _context.appoinment.Max(c => c.Contract) + 1;
                    if (appoinment.NCH1 > 0 || appoinment.NCH2 > 0 || appoinment.NCH3 > 0 || appoinment.NCH21 > 0)
                    {
                        appoinment.ph = _context.appoinment.Max(c => c.ph) + appoinment.NCH2 + appoinment.NCH1 + appoinment.NCH3 + appoinment.NCH21;
                        str          += "Căn hộ: " + Convert.ToString(appoinment.ph) + "\n";
                    }
                    if (appoinment.NSH > 0)
                    {
                        appoinment.psh = _context.appoinment.Max(c => c.psh) + appoinment.NSH;
                        str           += "Nhà phố: " + Convert.ToString(appoinment.psh) + "\n";
                    }
                    if (appoinment.NSHH > 0)
                    {
                        appoinment.pshh = _context.appoinment.Max(c => c.pshh) + appoinment.NSHH;
                        str            += "Shophouse: " + Convert.ToString(appoinment.pshh) + "\n";
                    }
                    if (appoinment.NMS > 0)
                    {
                        appoinment.pms = _context.appoinment.Max(c => c.pms) + appoinment.NMS;
                        str           += "Biệt thự: " + Convert.ToString(appoinment.pms) + "\n";
                    }
                    if (appoinment.NS > 0)
                    {
                        appoinment.pns = _context.appoinment.Max(c => c.pns) + appoinment.NS;
                        str           += "Shop (kios chung cư): " + Convert.ToString(appoinment.pns) + "\n";
                    }
                }
                else
                {
                    Random rd = new Random();
                    appoinment.Contract = rd.Next(100, 151);
                    if (appoinment.NCH1 > 0 || appoinment.NCH2 > 0 || appoinment.NCH3 > 0 || appoinment.NCH21 > 0)
                    {
                        appoinment.ph = rd.Next(100, 151);
                        str          += "Căn hộ: " + Convert.ToString(appoinment.ph) + "\n";
                    }
                    if (appoinment.NSH > 0)
                    {
                        appoinment.psh = rd.Next(100, 151);
                        str           += "Nhà phố: " + Convert.ToString(appoinment.psh) + "\n";
                    }
                    if (appoinment.NSHH > 0)
                    {
                        appoinment.pshh = rd.Next(100, 151);
                        str            += "Shophouse: " + Convert.ToString(appoinment.pshh) + "\n";
                    }
                    if (appoinment.NMS > 0)
                    {
                        appoinment.pms = rd.Next(100, 151);
                        str           += "Biệt thự: " + Convert.ToString(appoinment.pms) + "\n";
                    }
                }
                appoinment.IsActive = true;
                appoinment.New      = true;
                appoinment.Official = false;
                appoinment.cTime    = DateTime.Now.ToString("ddMMyyyy HH:mm:ss.FFFFFFF");
                appoinment.Confirm  = false;
                var customers = await _context.Customers.Where(c => c.CollaboratorsID == coll.ID).ToListAsync();

                foreach (var c in customers)
                {
                    if (c.phone == appoinment.Phone)
                    {
                        if (appoinment.supporter)
                        {
                            c.charges = 1.0;
                        }
                        else
                        {
                            c.charges = 1.3;
                        }
                        break;
                    }
                }
                _context.Add(appoinment);
                AppModal modal = new AppModal();
                modal.appoinment = appoinment;
                Collaborators co = _colls.Find(x => x.email == appoinment.sale);
                modal.collaborator = co;
                await _context.SaveChangesAsync();

                TempData["ct"] = appoinment.Contract;
                TempData["pt"] = str;
                return(View("Confirm", modal));
            }
            //}
            //return NotFound();
        }