public async Task <IActionResult> Edit(int id, [Bind("ID,Customer,Gender,Address,Phone,Email,Job,WorkPlace,Cmnd,Day,Place,Money,Purpose,Requires,Price,Details,DType,Cash,NCH1,NCH2,NCH3,NMS,NSHH,NSH,HKTT,sale,password,Contract, Priority, Confirm")] Appoinment appoinment)
        {
            if (id != appoinment.ID)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(appoinment);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!AppoinmentExists(appoinment.ID))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(appoinment));
        }
        public async Task <IActionResult> Edit(int id, [Bind("ID,name,phone,email,pass")] Sale sale)
        {
            if (id != sale.ID)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(sale);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!SaleExists(sale.ID))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(sale));
        }
Пример #3
0
        public async Task <IActionResult> Approve([Bind("Id", "Status", "RequestName", "Subject", "Contents")] Request request)
        {
            var curUser = await _userManager.GetUserAsync(User);

            var authorized = await IsAuthorized(curUser, "Requests", "Update");

            if (!authorized)
            {
                return(View("AccessDenied"));
            }
            if (!ModelState.IsValid)
            {
                TempData["StatusMessage"] = "Can't find request!";
                return(View());
            }
            TempData["StatusMessage"] = "Request has been updated!";
            var tmp = await _context.Requests.FindAsync(request.Id);

            tmp.Status = request.Status;
            if (request.Status == Status.Accepted)
            {
                //string contents = "Yêu cầu của bạn đã được thông qua.";
                //SendMail(request.Subject, new MailboxAddress("Hương Ngô", "*****@*****.**"), contents);
            }
            _context.Update(tmp);
            await _context.SaveChangesAsync();

            return(View());
        }
Пример #4
0
        public async Task <IActionResult> RequestsControl()
        {
            //var curUser = await _userManager.GetUserAsync(User);
            //var authorized = await IsAuthorized(curUser, "Contracts", "Create");
            //TempData["StatusMessage"] = TempData["StatusMessage"];
            //if (!authorized)
            //{
            //    return View("AccessDenied");
            //}
            var requests = await _context.Requests.Where(r => r.Subject == "Loan").ToListAsync();

            if (requests == null)
            {
                return(NotFound("Can't find any requests"));
            }
            var curUser = await _userManager.GetUserAsync(User);

            var authorized = await IsAuthorized(curUser, "Requests", "List");

            TempData["StatusMessage"] = TempData["StatusMessage"];
            if (!authorized)
            {
                return(View("AccessDenied"));
            }
            foreach (Request request in requests)
            {
                if (request.OwnerId != null)
                {
                    request.Owner = await _context.sale.FirstAsync(s => s.Id == request.OwnerId);
                }
                _context.Update(request);
            }
            return(View(requests));
        }
Пример #5
0
        public async Task <IActionResult> PassportInfo(Guid id, [Bind("Id, Cmnd, Day, Place, HKTT, Address")] Appoinment app)
        {
            var appoinment = await _context.appoinment.FirstOrDefaultAsync(e => e.Id == id);

            if (appoinment == null)
            {
                return(NotFound());
            }
            appoinment.Cmnd    = app.Cmnd;
            appoinment.Day     = app.Day;
            appoinment.Place   = app.Place;
            appoinment.HKTT    = app.HKTT;
            appoinment.Address = app.Address;
            _context.Update(appoinment);
            try
            {
                await _context.SaveChangesAsync();
            }
            catch (System.Exception)
            {
                return(NotFound());
            }
            return(RedirectToAction(nameof(Dashboard)));
        }
        public async Task <IActionResult> Create([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, NSH1, PlanId, supporter, IdType, IsForeigner, View, Direction, Acreage, Floor")] Appoinment appoinment, List <IFormFile> files)
        {
            //if (ModelState.IsValid)
            //{
            var contact = await _context.Contacts.FirstOrDefaultAsync(c => c.Phone == appoinment.Phone);

            if (contact != null)
            {
                contact.Appoinment = appoinment;
                _context.Update(contact);
            }
            var curUser = await _userManager.GetUserAsync(User);

            var authorized = await IsAuthorized(curUser, "Contracts", "Create");

            if (!authorized || curUser.EmailConfirmed == false)
            {
                return(View("AccessDenied"));
            }
            if (curUser != null)
            {
                var roles = await _userManager.GetRolesAsync(curUser);

                if (roles.Contains("Collaborator"))
                {
                    if (contact != null)
                    {
                        contact.Charges = appoinment.supporter == true ? 1.0 : 1.3;
                        _context.Update(contact);
                    }
                }
            }
            PasswordHasher <Sale>      hasher = new PasswordHasher <Sale>();
            PasswordVerificationResult result = hasher.VerifyHashedPassword(curUser, curUser.PasswordHash, appoinment.password);

            if (result == PasswordVerificationResult.Failed)
            {
                TempData["StatusMessage"] = "Sai mật khẩu xác nhận";
                return(RedirectToAction("Create"));
            }
            appoinment.password    = hasher.HashPassword(curUser, appoinment.password);
            appoinment.SaleDetails = curUser.Info;
            appoinment.Sale        = curUser;
            appoinment.SEmail      = curUser.Email;
            ViewBag.plan           = await _context.Plans.ToListAsync();

            string str = "";

            if (appoinment.Sale == null)
            {
                TempData["StatusMessage"] = "Bạn chưa đăng nhập vào hệ thống";
                return(RedirectToAction("Create"));
            }
            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.Where(a => a.IsActive == true).Max(c => c.Contract) + 1;
                    if (appoinment.NCH1 > 0 || appoinment.NCH2 > 0 || appoinment.NCH3 > 0 || appoinment.NCH21 > 0)
                    {
                        appoinment.ph = _context.appoinment.Where(a => a.IsActive == true).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.Where(a => a.IsActive == true).Max(c => c.psh) + appoinment.NSH;
                        str           += "Biệt thự ĐL: " + Convert.ToString(appoinment.psh) + "\n";
                    }
                    if (appoinment.NSH1 > 0)
                    {
                        appoinment.psh1 = _context.appoinment.Where(a => a.IsActive == true).Max(c => c.psh1) + appoinment.NSH1;
                        str            += "Biệt thự SL: " + Convert.ToString(appoinment.psh1) + "\n";
                    }
                    if (appoinment.NSHH > 0)
                    {
                        appoinment.pshh = _context.appoinment.Where(a => a.IsActive == true).Max(c => c.pshh) + appoinment.NSHH;
                        str            += "Shophouse: " + Convert.ToString(appoinment.pshh) + "\n";
                    }
                    if (appoinment.NMS > 0)
                    {
                        appoinment.pms = _context.appoinment.Where(a => a.IsActive == true).Max(c => c.pms) + appoinment.NMS;
                        str           += "Biệt thự: " + Convert.ToString(appoinment.pms) + "\n";
                    }
                    if (appoinment.NS > 0)
                    {
                        appoinment.pns = _context.appoinment.Where(a => a.IsActive == true).Max(c => c.pns) + appoinment.NS;
                        str           += "Shop (kios chung cư): " + Convert.ToString(appoinment.pns) + "\n";
                    }
                }
                //appoinment.supporter = false;
                appoinment.New      = true;
                appoinment.Official = false;
                appoinment.cTime    = DateTime.Now.ToString("ddMMyyyy HH:mm:ss.FFFFFFF");
                appoinment.Confirm  = false;
                appoinment.IsActive = true;
                //var p = await _context.Plans.SingleOrDefaultAsync(pl => pl.Id == plan);
                //if (p == null)
                //{
                //    TempData["StatusMessage"] = "Bạn chưa chọn dự án";
                //    return View();
                //}
                var           newFileName = string.Empty;
                List <string> portrait    = new List <string>();
                if (files != null)
                {
                    var    fileName = string.Empty;
                    string PathDB   = string.Empty;

                    foreach (var file in files)
                    {
                        if (file.Length > 0)
                        {
                            //Getting FileName
                            fileName = ContentDispositionHeaderValue.Parse(file.ContentDisposition).FileName.Trim('"');

                            //Assigning Unique Filename (Guid)
                            var myUniqueFileName = Convert.ToString(Guid.NewGuid());

                            //Getting file Extension
                            var FileExtension = Path.GetExtension(fileName);

                            // concating  FileName + FileExtension
                            newFileName = myUniqueFileName + FileExtension;

                            // Combines two strings into a path.
                            fileName = Path.Combine(_environment.WebRootPath, "storage") + $@"\{newFileName}";

                            // if you want to store path of folder in database

                            portrait.Add(newFileName);

                            using (FileStream fs = System.IO.File.Create(fileName))
                            {
                                file.CopyTo(fs);
                                fs.Flush();
                            }
                        }
                    }
                    if (portrait.Count > 1)
                    {
                        appoinment.Photo = portrait[0] + " " + portrait[1];
                    }
                    else if (portrait.Count > 0)
                    {
                        appoinment.Photo = portrait[0];
                    }
                }

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

                //string contents = curUser.Name + " đã tạo một HĐ mới trên hệ thống AnnSmart" + " vào lúc " + DateTime.Now.ToString("HH:mm:ss MM-dd-yyyy");
                //SendMail("HĐ đặt chỗ", new MailboxAddress("Hương Ngô", "*****@*****.**"), contents);

                TempData["ct"] = appoinment.Contract;
                TempData["pt"] = str;
                return(RedirectToAction("Confirm", new { appoinment.Id }));
            }
        }