private void btnEdit_Click(object sender, EventArgs e)
        {
            string userName = txtID.Text;
            string Add      = txtDiaChi.Text;
            string Phone    = txtSDT.Text;
            string name     = txtHoTen.Text;

            if (userName == "")
            {
                MessageBox.Show("Nhấp chọn vào nhân viên cần edit", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }
            if (Add == "" || Phone == "" || name == "")
            {
                MessageBox.Show("Thông tin không được để trông", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }
            var user = db.NhanViens.Where(s => s.MaNv == userName).FirstOrDefault();

            if (user != null)
            {
                //DataGridViewRow row = this.dgvListNV.Rows[local];
                var query = ("Update NhanVien set TenNV = N'" + txtHoTen.Text + "' ,DiaChi = N'" + txtDiaChi.Text + "',SDT='" + txtSDT.Text + "' where MaNV=N'" + txtID.Text + "'");
                db.Database.ExecuteSqlCommand(query);
                db.SaveChanges();
                Entities3 a   = new Entities3();
                var       lst = a.NhanViens.ToList();
                dgvListNV.DataSource = lst;
            }
            else
            {
                MessageBox.Show("Không tìm thấy ID trong database", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }
Exemple #2
0
        public ActionResult AddStaff(RegisterViewModel newModel)
        {
            var userStore = new UserStore <IdentityUser>();
            var manager   = new UserManager <IdentityUser>(userStore);

            var user = new IdentityUser()
            {
                Email = newModel.Email, UserName = newModel.Email
            };
            IdentityResult result = manager.Create(user, newModel.Password);

            try
            {
                // traversing the database
                using (Entities3 db = new Entities3())
                {
                    // executing SQL comman
                    db.Database.ExecuteSqlCommand("insert into [dbo].[userrolesbridging]([UserId], [RoleId]) values ('" + user.Id + "',2);");
                }
                ModelState.Clear();
                ViewBag.Message = "success";
                return(View());
            }
            catch
            {
                ViewBag.Message = "error";
                return(View());
            }
        }
Exemple #3
0
        public ActionResult ShowDetails(string query, int query2)
        {
            using (var context = new Entities3())
            {
                // for implementing the functionality of staff member checking booking details
                var customerDetails = (from u in context.AspNetUsers
                                       where u.Id == query
                                       select new CustomerModel()
                {
                    Id = u.Id, Email = u.Email
                }).ToArray();
                var customerBookingDetails = (from bd in context.CustomerBookings
                                              where bd.customer_booking_id == query2
                                              select new
                                              CustomerBookingModelForStaff()
                {
                    customer_booking_id = bd.customer_booking_id,
                    vehicle_id = bd.vehicle_id, to_date = bd.to_date,
                    from_date = bd.from_date
                }).ToList();

                var customerBookingLocations = (from c in context.CustomerBookingLocations
                                                where c.customer_booking_id == query2
                                                select new CustomerBookingLocationForStaff()
                {
                    longitude = c.longitude, latitude = c.latitude
                }).ToList();
                ViewBag.customerDetails          = customerDetails;
                ViewBag.customerBookingDetails   = customerBookingDetails;
                ViewBag.customerBookingLocations = customerBookingLocations;
                return(View());
            }
        }
Exemple #4
0
        public ActionResult AddVehicle(StaffCarUploadModel newUpload)
        {
            //bd44b938 - 8f13 - 45c4 - 96ee - 08dd988b5d9c
            string path     = Server.MapPath("~/App_Data/File");
            string fileName = Path.GetFileName(newUpload.carPicture.FileName);
            string fullPath = Path.Combine(path, fileName);
            string userId   = User.Identity.GetUserId();

            try
            {
                using (Entities3 db = new Entities3())
                {
                    // This sql command inserts a vehicle into the database.
                    db.Database.ExecuteSqlCommand("insert into [dbo].[Vehicle] ([Name],[Model],[userId],[image_path]) Values ('" + newUpload.name + "', '" + newUpload.model + "', '" + userId + "', '" + fullPath + "');");
                }
                newUpload.carPicture.SaveAs(fullPath);
                ViewBag.Message = "success";
            }
            catch
            {
                ViewBag.Message = "error";
            }

            return(View());
        }
 public ActionResult Index()
 {
     // checks if the user is authenticated
     if (User.Identity.IsAuthenticated)
     {
         //gets the current user
         string currentUserId = User.Identity.GetUserId();
         using (var context = new Entities3())
         {
             // finds the role of the user. This is done to show specific navigation bar
             // to specific roles of users.
             var result = (from u in context.AspNetUsers
                           join ur in context.userrolesbridgings on u.Id equals ur.UserId
                           join ro in context.AspNetRoles on
                           ur.RoleId equals ro.Id
                           where u.Id == currentUserId
                           select ro.Name).ToArray();
             ViewBag.message = result[0];
         }
     }
     else
     {
         ViewBag.message = "nothing";
     }
     return(View());
 }
Exemple #6
0
        public ActionResult ViewFleet()
        {
            Entities3 db = new Entities3();

            ViewBag.first    = db.AspNetUsers.ToList();
            ViewBag.ItemData = db.Vehicles.ToList();
            return(View());
        }
Exemple #7
0
 public EmptyResult DeleteLocations()
 {
     using (var context = new Entities3())
     {
     }
     return(null);
     // return View();
 }
Exemple #8
0
 // GET: Customer
 // This controller loads the index page with data from the database.
 public ActionResult Index()
 {
     using (var context = new Entities3())
     {
         //ViewBag.ItemData = db.Vehicles.ToList();
         ViewBag.ItemData = context.Vehicles.ToList();
     }
     return(View());
 }
Exemple #9
0
        // This controller opens the bulk email page

        public ActionResult SendBulkEmail()
        {
            using (var context = new Entities3())
            {
                var req = (from u in context.AspNetUsers select u.Email).ToList();
                ViewBag.emails = req;
            }
            return(View());
        }
Exemple #10
0
 // This function checks the role of the user trying to login by
 // checking the email with the userroles from the database
 public String[] roleChecker(string email)
 {
     using (var context = new Entities3())
     {
         var result = (from u in context.AspNetUsers join ur in context.userrolesbridgings
                       on u.Id equals ur.UserId join ro in context.AspNetRoles on
                       ur.RoleId equals ro.Id where u.Email == email
                       select ro.Name).ToArray();
         return(result);
     }
     return(null);
 }
Exemple #11
0
        public ActionResult SendBulkEmail(BulkEmailViewModel emailMessage)
        {
            if (emailMessage.messageSubject == null ||
                emailMessage.messageBody == null)
            {
                ViewBag.Result = "error";
                return(View());
            }
            else
            {
                try
                {
                    String to = "";
                    using (var context = new Entities3())
                    {
                        var req = (from u in context.AspNetUsers select u.Email).ToList();
                        to = req[0];
                        for (int i = 1; i < req.Count(); i++)
                        {
                            to = to + "," + req[i];
                        }
                    }
                    String messageSubject   = emailMessage.messageSubject;
                    String messageBody      = emailMessage.messageBody;
                    BulkEmailSenderClass bs = new BulkEmailSenderClass();

                    if (emailMessage.attachment != null)
                    {
                        string path     = Server.MapPath("~/App_Data/File");
                        string fileName = Path.GetFileName(emailMessage.attachment.FileName);
                        string fullPath = Path.Combine(path, fileName);
                        emailMessage.attachment.SaveAs(fullPath);
                        bs.send(to, messageSubject, messageBody, fullPath, fileName);
                    }
                    else
                    {
                        bs.send(to, messageSubject, messageBody, "nothing", "nothing");
                    }
                    ModelState.Clear();
                    ViewBag.Result = "success";
                    return(View());
                }
                catch (Exception e)
                {
                    ViewBag.Result = "error";
                    return(View());
                }
            }
        }
Exemple #12
0
        public async Task <ActionResult> ExternalLoginConfirmation(ExternalLoginConfirmationViewModel model, string returnUrl)
        {
            if (User.Identity.IsAuthenticated)
            {
                return(RedirectToAction("Index", "Manage"));
            }

            if (ModelState.IsValid)
            {
                // Get the information about the user from the external login provider
                var info = await AuthenticationManager.GetExternalLoginInfoAsync();

                if (info == null)
                {
                    return(View("ExternalLoginFailure"));
                }
                var user = new ApplicationUser {
                    UserName = model.Email, Email = model.Email
                };
                var result = await UserManager.CreateAsync(user);

                if (result.Succeeded)
                {
                    result = await UserManager.AddLoginAsync(user.Id, info.Login);

                    using (Entities3 db = new Entities3())
                    {
                        db.Database.ExecuteSqlCommand("insert into [dbo].[userrolesbridging]([UserId], [RoleId]) values ('" + user.Id + "',3);");
                    }

                    if (result.Succeeded)
                    {
                        await SignInManager.SignInAsync(user, isPersistent : false, rememberBrowser : false);

                        return(RedirectToLocal(returnUrl));
                    }
                }
                AddErrors(result);
            }

            ViewBag.ReturnUrl = returnUrl;
            return(View(model));
        }
Exemple #13
0
        public JsonResult CheckBookingDate(string inputDates)
        {
            var response = "";

            String[] spearator           = { "," };
            String[] result              = inputDates.Split(spearator, StringSplitOptions.RemoveEmptyEntries);
            int      car_id              = Int32.Parse(result[0].Trim('\t', '"'));
            DateTime date_from           = Convert.ToDateTime(result[1].Trim('\t', '"'));
            DateTime date_to             = Convert.ToDateTime(result[2].Trim('\t', '"'));
            var      date_from_converted = date_from.ToString("yyyy-MM-dd");
            var      date_to_converted   = date_to.ToString("yyyy-MM-dd");
            DateTime date_from_date      = Convert.ToDateTime(date_from_converted);
            DateTime date_to_date        = Convert.ToDateTime(date_to_converted);

            using (var context = new Entities3())
            {
                try
                {
                    // Linq command where my booking constraint is implemented
                    var isBooked = (from c in context.CustomerBookings
                                    where ((c.from_date >= date_from_date && c.from_date <= date_to_date) ||
                                           (c.to_date >= date_to_date && c.to_date <= date_to_date) ||
                                           (c.from_date <= date_from_date && c.to_date >= date_to_date)) &&
                                    c.vehicle_id == car_id
                                    select c.vehicle_id).ToList();
                    Console.WriteLine(isBooked);
                    if (isBooked.Count > 0)
                    {
                        response = "already booked";
                    }
                    else
                    {
                        response = "not booked";
                    }
                }
                catch (Exception e)
                {
                    Console.WriteLine(e);
                }
            }
            return(Json(response, JsonRequestBehavior.AllowGet));
        }
Exemple #14
0
        public JsonResult ShowAnalytics()
        {
            AdminAnalyticsUserAmount userAnalytics = new AdminAnalyticsUserAmount();

            using (var context = new Entities3())
            {
                string num  = "2";
                string num2 = "3";
                // Linq statement to find data for analytics
                userAnalytics.customerNumber = (from u in context.AspNetUsers join roles in context.userrolesbridgings
                                                on u.Id equals roles.UserId where roles.RoleId == num2 select u.Id).ToList().Count();
                userAnalytics.staffNumber = (from u in context.AspNetUsers join roles in context.userrolesbridgings on u.Id equals roles.UserId
                                             where roles.RoleId == num select u.Id).ToList().Count();
            }
            // serializing the object to make it easier to send it by json response
            JavaScriptSerializer js = new JavaScriptSerializer();
            var json = js.Serialize(userAnalytics);

            return(Json(json, JsonRequestBehavior.AllowGet));
        }
Exemple #15
0
        // GET: Staff
        public ActionResult Index()
        {
            // gets the current user
            string userId = User.Identity.GetUserId();

            using (var context = new Entities3())
            {
                // collects all the staff data and puts them inside ViewBag.
                var viewModel = (from u in context.AspNetUsers join c in context.CustomerBookings
                                 on u.Id equals c.userId
                                 select new StaffViewCustomerBookingInDashboard()
                {
                    Id = u.Id, Email = u.Email,
                    customer_booking_id = c.customer_booking_id, from_date = c.from_date,
                    to_date = c.to_date, vehicle_id = c.vehicle_id
                }).ToList();
                ViewBag.itemData = viewModel;
                return(View());
            }
        }
Exemple #16
0
        public async Task <ActionResult> Register(RegisterViewModel model)
        {
            if (ModelState.IsValid)
            {
                var user = new ApplicationUser {
                    UserName = model.Email, Email = model.Email
                };
                var result = await UserManager.CreateAsync(user, model.Password);

                if (result.Succeeded)
                {
                    // This saves the user added as customer
                    if (model.isStaff == "false")
                    {
                        string userId = user.Id;
                        using (Entities3 db = new Entities3())
                        {
                            db.Database.ExecuteSqlCommand("insert into [dbo].[userrolesbridging]([UserId], [RoleId]) values ('" + user.Id + "',3);");
                        }
                    }

                    await SignInManager.SignInAsync(user, isPersistent : false, rememberBrowser : false);

                    // For more information on how to enable account confirmation and password reset please visit https://go.microsoft.com/fwlink/?LinkID=320771
                    // Send an email with this link
                    // string code = await UserManager.GenerateEmailConfirmationTokenAsync(user.Id);
                    // var callbackUrl = Url.Action("ConfirmEmail", "Account", new { userId = user.Id, code = code }, protocol: Request.Url.Scheme);
                    // await UserManager.SendEmailAsync(user.Id, "Confirm your account", "Please confirm your account by clicking <a href=\"" + callbackUrl + "\">here</a>");

                    return(RedirectToAction("Index", "Home"));
                }
                AddErrors(result);
            }

            // If we got this far, something failed, redisplay form
            return(View(model));
        }
Exemple #17
0
        public ActionResult Index(user_table usr)
        {
            //get username and password from the user
            //check it against the database user table

            Entities3 dbObject  = new Entities3();
            var       checkUser = dbObject.user_tables.Where(l => l.user_name.Equals(usr.user_name) && l.user_password.Equals(usr.user_password)).FirstOrDefault();

            if (checkUser != null)
            {
                var loggeduser = dbObject.user_tables.Where(l => l.user_name.Equals(usr.user_name)).FirstOrDefault();
                Session["user_name"] = loggeduser.user_name.ToString();
                Session["u_id"]      = loggeduser.u_id.ToString();
                Session["user_type"] = loggeduser.user_type.ToString();


                return(RedirectToAction("Dashboard"));
            }
            else
            {
                ViewBag.msg = "Invalid Username or Password";
            }
            return(View());
        }
        public IHttpActionResult getmembersbyid(string id)
        {
            List <getmemberID_Result> x = new List <getmemberID_Result>();
            var test    = new Entities3();
            var reslist = test.getmemberID(id).ToList();

            foreach (var pen in reslist.ToList())
            {
                x.Add(
                    new getmemberID_Result
                {
                    DISTR_ID    = pen.DISTR_ID,
                    ANAME       = pen.ANAME,
                    DISTR_IDENT = pen.DISTR_IDENT,
                    ADDRESS     = pen.ADDRESS,
                    TELEPHONE   = pen.TELEPHONE,
                    E_MAIL      = pen.E_MAIL,
                    AREA_ID     = pen.AREA_ID,
                    AREA_NAME   = pen.AREA_NAME
                }
                    );
            }
            return(Ok(x));
        }
Exemple #19
0
        public JsonResult CreateBooking(string sendInfo)
        {
            string userId = User.Identity.GetUserId();
            //string date_from;
            //string date_to;
            string car_id;
            string latitude;
            string longitude;
            double distance = 0.0;
            double price    = 0.0;

            List <LocationModel> location = new List <LocationModel>();

            String[] spearator = { "," };
            String[] result    = sendInfo.Split(spearator, StringSplitOptions.RemoveEmptyEntries);
            foreach (String s in result)
            {
                Console.WriteLine(result);
            }

            DateTime date_from           = Convert.ToDateTime(result[0].Trim('\t', '[', '"'));
            DateTime date_to             = Convert.ToDateTime(result[1].Trim('\t', '[', '"'));
            var      date_from_converted = date_from.ToString("yyyy-MM-dd");
            var      date_to_converted   = date_to.ToString("yyyy-MM-dd");
            DateTime date_from_date      = Convert.ToDateTime(date_from_converted);
            DateTime date_to_date        = Convert.ToDateTime(date_to_converted);

            car_id = result[2].Trim('\t', '[', '"');
            var abc = result[3].Trim('\t', '[', '"');

            distance = Convert.ToDouble(abc);
            var vehicle_id = Int32.Parse(car_id);

            price = distance * 3;
            try
            {
                using (var context = new Entities3())
                {
                    // this SQL command is executed to insert the booking into the database
                    context.Database.ExecuteSqlCommand("insert into " +
                                                       "[dbo].[CustomerBooking]([userId],[vehicle_id]," +
                                                       "[isAccepted],[to_date],[from_date],[pickup_location],[dropoff_location],[distance],[price]) " +
                                                       "values('" + userId + "', '" + car_id + "', 'false', '" + date_to_converted + "'," +
                                                       "'" + date_from_converted + "','location1','location2', '" + distance + "', '" + price + "')");
                    var lastId = (from c in context.CustomerBookings
                                  where c.userId == userId && c.vehicle_id == vehicle_id
                                  select c.customer_booking_id).ToArray();
                    for (int i = 4; i <= result.Length - 2; i = i + 2)
                    {
                        latitude = result[i].Trim('[', ']');
                        int j = i;
                        longitude = result[j + 1].Trim('[', ']');
                        context.Database.ExecuteSqlCommand("insert into " +
                                                           "[dbo].[CustomerBookingLocation](customer_booking_id,latitude,longitude)" +
                                                           "values('" + lastId[0] + "', '" + latitude + "', '" + longitude + "')");
                    }
                }
            }
            catch (Exception e)
            {
                return(Json("error", JsonRequestBehavior.AllowGet));
            }
            CustomerResponse cs = new CustomerResponse();

            cs.response = "success";
            cs.distance = distance;
            cs.price    = price;
            cs.message  = "Thank you for using our services. Our staff will be in contact with you soon.";

            JavaScriptSerializer js = new JavaScriptSerializer();
            var json = js.Serialize(cs);

            return(Json(json, JsonRequestBehavior.AllowGet));
        }