Beispiel #1
0
        public ActionResult Add()
        {
            if (Session["UserData"] is Admin)
            {
                var currentUser = Session["UserData"] as Admin;
                var distributors = GetDistributors(currentUser.UserId.ToString());
                var distributorsSelectList =
                    new SelectList(
                        distributors.Select(
                            dist => new SelectListItem() { Text = dist.Username, Value = dist.UserId.ToString() }), "Value",
                        "Text");

                ViewData["DistributorList"] = distributorsSelectList;
                var currentUsers = Session["UserData"] as Admin;
                var dealers = GetDealers(currentUsers.UserId.ToString());
                var dealerSelectList =
                    new SelectList(
                        dealers.Select(
                            deal => new SelectListItem() { Text = deal.Username, Value = deal.UserId.ToString() }), "Value",
                        "Text");

                ViewData["dealerList"] = dealerSelectList;
                var customers = GetCustomers(currentUser.UserId.ToString());
                var customerSelectList =
                    new SelectList(
                        customers.Select(cust => new SelectListItem() { Text = cust.Username, Value = cust.UserId.ToString() }), "Value", "Text");
                ViewData["customerList"] = customerSelectList;
                var vehicles = GetVehicles(currentUser.UserId.ToString());
                var vehicleSelectList =
                    new SelectList(
                        vehicles.Select(cust => new SelectListItem() { Text = cust.VehicleNo, Value = cust.VehicleId.ToString() }), "Value", "Text");
                ViewData["vehicleList"] = vehicleSelectList;
            }

            //return View(new VehicleViewModel());
            DeviceViewModel device = new DeviceViewModel();
            // DeviceMapping devicemap = new DeviceMapping();
            if (Request.IsAjaxRequest())
            {
                return PartialView("_Add", device);
            }
            return View(device);
        }
Beispiel #2
0
        public ActionResult Add(DeviceViewModel module)
        {
            HttpPostedFileBase file = Request.Files["fileUpload"];
            if (ModelState.IsValid)
            {
                try
                {
                    var device = Mapper.Map<DeviceViewModel, Device>(module);
                    // var devicemapping = Mapper.Map<DeviceMap, Models.DeviceMapping>(modum);
                    if (Session["UserData"] is Distributor)
                    {
                        device.CustomerId = ((Distributor)Session["UserData"]).UserId;
                    }
                    else
                    {
                        device.CustomerId = Guid.Parse(Request.Form["customerId"]);
                        device.VehicleId = Guid.Parse(Request.Form["vehicleId"]);
                        device.ImageName = file.FileName;
                        device.Image = ConvertToBytes(file);
                    }

                    // Models.DeviceMapping devicemap = new Models.DeviceMapping();
                    // var devicemap = new DeviceMapping();

                    //devicemap.VehicleId = Guid.Parse(Request.Form["vehicleId"]);
                    //devicemap.DeviceId = Guid.Parse(module.DeviceId.ToString());

                    //mapping.deviceMap.Add(devicemap);
                    //mapping.SaveChanges();

                    _deviceServce.CreateDevice(device);
                    _deviceServce.SaveDevice();

                    return RedirectToAction("Index", "Device");
                }

                catch (InvalidOperationException ex)
                {
                    ModelState.AddModelError("Error", ex.Message);
                }

                catch (Exception ex)
                {
                    ModelState.AddModelError("Error", ex.Message);
                }
            }

            if (Request.IsAjaxRequest())
                return PartialView("_Add", module);

            return View(module);
        }
Beispiel #3
0
        public ActionResult Edit(DeviceViewModel module)
        {
            //model.Password = "******";
            if (Session["UserData"] is Admin)
            {
                module.CustomerId = Guid.Parse(Request.Form["customerId"]);
            }
            HttpPostedFileBase file = Request.Files["fileUpload"];

            if (ModelState.IsValid)
            {
                try
                {
                    if (module.DeviceId == Guid.Empty)
                    {
                        module.DeviceId = Guid.NewGuid();
                        var device = Mapper.Map<DeviceViewModel, Device>(module);
                        // var devicemapping = Mapper.Map<DeviceMap, Models.DeviceMapping>(modum);
                        device.CustomerId = Guid.Parse(Request.Form["customerId"]);
                        device.VehicleId = Guid.Parse(Request.Form["vehicleId"]);
                        if (file != null)
                        {
                            device.ImageName = file.FileName;
                            device.Image = ConvertToBytes(file);
                        }
                        _deviceServce.CreateDevice(device);
                    }
                    else
                    {
                        var device = _deviceServce.GetDevice(module.DeviceId);
                        Mapper.Map<DeviceViewModel, Device>(module, device);
                        _deviceServce.UpdateDevice(device);
                    }
                    _deviceServce.SaveDevice();

                    return Json(new { Result = "Success" });
                }
                catch (Exception ex)
                {

                }
            }

            if (Session["UserData"] is Admin)
            {
                var currentUser = Session["UserData"] as Admin;
                var distributors = GetDistributors(currentUser.UserId.ToString());
                var distributorsSelectList =
                    new SelectList(
                        distributors.Select(
                            dist => new SelectListItem() { Text = dist.Username, Value = dist.UserId.ToString() }), "Value",
                        "Text", module.CustomerId.ToString());

                ViewData["DistributorList"] = distributorsSelectList;
                var dealers = GetDealers(currentUser.UserId.ToString());
                var dealersSelectList = new SelectList(
                                             dealers.Select(deal => new SelectListItem() { Text = deal.Username, Value = deal.UserId.ToString() }), "Value", "Text");
                ViewData["DealerList"] = dealersSelectList;
                var customers = GetCustomers(currentUser.UserId.ToString());
                var customersSelectList = new SelectList(
                                             customers.Select(cust => new SelectListItem() { Text = cust.Username, Value = cust.UserId.ToString() }), "Value", "Text");
                ViewData["customerList"] = customersSelectList;
                var vehicles = GetVehicles(currentUser.UserId.ToString());
                var vehicleSelectList =
                    new SelectList(
                        vehicles.Select(cust => new SelectListItem() { Text = cust.VehicleNo, Value = cust.VehicleId.ToString() }), "Value", "Text");
                ViewData["vehicleList"] = vehicleSelectList;

            }
            return PartialView("_Edit", module);
        }
Beispiel #4
0
        // GET : /Distributor/Edit
        public ActionResult Edit(string deviceId)
        {
            DeviceViewModel deviceVM = new DeviceViewModel();
            try
            {
                if (Session["UserData"] is Admin)
                {
                    var currentUser = Session["UserData"] as Admin;
                    var distributors = GetDistributors(currentUser.UserId.ToString());
                    var distributorsSelectList =
                        new SelectList(
                            distributors.Select(
                                dist => new SelectListItem() { Text = dist.Username, Value = dist.UserId.ToString() }), "Value",
                            "Text", deviceVM.DeviceId.ToString());

                    ViewData["DistributorList"] = distributorsSelectList;

                    var dealers = GetDealers(currentUser.UserId.ToString());
                    var dealersSelectList = new SelectList(
                                                 dealers.Select(deal => new SelectListItem() { Text = deal.Username, Value = deal.UserId.ToString() }), "Value", "Text");
                    ViewData["DealerList"] = dealersSelectList;
                    var customers = GetCustomers(currentUser.UserId.ToString());
                    var customersSelectList = new SelectList(
                                                 customers.Select(cust => new SelectListItem() { Text = cust.Username, Value = cust.UserId.ToString() }), "Value", "Text");
                    ViewData["customerList"] = customersSelectList;
                    var vehicles = GetVehicles(currentUser.UserId.ToString());
                    var vehicleSelectList =
                        new SelectList(
                            vehicles.Select(cust => new SelectListItem() { Text = cust.VehicleNo, Value = cust.VehicleId.ToString() }), "Value", "Text");
                    ViewData["vehicleList"] = vehicleSelectList;

                    if (string.IsNullOrWhiteSpace(deviceId))
                    {
                        deviceVM.DeviceId = Guid.Empty;
                    }
                    else
                    {
                        var deviceGuid = Guid.Parse(deviceId);
                        Device device = _deviceServce.GetDevice(deviceGuid);
                        deviceVM = Mapper.Map<Device, DeviceViewModel>(device);
                    }
                }
                    return PartialView("_Edit", deviceVM);
            }
            catch (Exception ex)
            {
                //     Logger.ErrorFormat("Controller : {0} - Action : {1}, Message : {2}", this.ControllerContext.RouteData.Values["controller"].ToString(), this.ControllerContext.RouteData.Values["action"].ToString(), ex.Message);
            }

            return View(deviceVM);
        }