public ActionResult DeleteCustomer(int id)
 {
     try
     {
         using (MOBILESHOPEntities dbcontext = new MOBILESHOPEntities())
         {
             var cstmr = dbcontext.mbshop_device_detail.Find(id);
             if (cstmr != null)
             {
                 var customer = dbcontext.mbshop_customer_details.Find(cstmr.mbshop_customer_details.customer_id);
                 dbcontext.mbshop_device_detail.Remove(cstmr);
                 dbcontext.SaveChanges();
                 if (customer != null)
                 {
                     dbcontext.mbshop_customer_details.Remove(customer);
                     dbcontext.SaveChanges();
                 }
                 return(Json(new { key = true, value = "Device Details deleted successfully" }, JsonRequestBehavior.AllowGet));
             }
             else
             {
                 return(Json(new { key = false, value = "Device Details not Found its Deleted from data base!!" }, JsonRequestBehavior.AllowGet));
             }
         };
     }
     catch (Exception)
     {
         return(Json(new { key = false, value = "Unable to the Customer" }, JsonRequestBehavior.AllowGet));
     }
 }
 public ActionResult SaveServices(int deviceId, string[] servicesId)
 {
     try
     {
         using (MOBILESHOPEntities dbcontext = new MOBILESHOPEntities())
         {
             var list = dbcontext.Costumer_Device_Services.Where(x => x.cds_device_key == deviceId).ToList();
             if (list.Any())
             {
                 foreach (var item in list)
                 {
                     dbcontext.Costumer_Device_Services.Remove(item);
                     dbcontext.SaveChanges();
                 }
             }
             foreach (var item in servicesId)
             {
                 int serviceKey = Convert.ToInt32(item);
                 Costumer_Device_Services service = new Costumer_Device_Services()
                 {
                     cds_service_key = serviceKey,
                     cds_device_key  = deviceId,
                 };
                 dbcontext.Costumer_Device_Services.Add(service);
                 dbcontext.SaveChanges();
             }
             return(Json(new { key = true, value = "Services added successfully" }, JsonRequestBehavior.AllowGet));
         };
     }
     catch (Exception ex)
     {
         return(Json(new { key = false, value = "Unable to process your request please contact to your admin." }, JsonRequestBehavior.AllowGet));
     }
 }
Пример #3
0
        public ActionResult AddOrUpdateModel(ModelDTO dto)

        {
            try
            {
                if (ModelState.IsValid)
                {
                    using (MOBILESHOPEntities dbcontext = new MOBILESHOPEntities())
                    {
                        if (dto.id == 0)
                        {
                            mb_model_detail mbModel = new mb_model_detail()
                            {
                                model_name      = dto.modelName,
                                model_brand_key = dto.Brand
                            };
                            dbcontext.mb_model_detail.Add(mbModel);
                            dbcontext.SaveChanges();
                            return(Json(new { key = true, value = "model added successfully" }, JsonRequestBehavior.AllowGet));
                        }

                        else
                        {
                            var model = dbcontext.mb_model_detail.Find(dto.id);
                            if (model != null)
                            {
                                model.model_name      = dto.modelName;
                                model.model_brand_key = dto.Brand;
                                dbcontext.SaveChanges();
                                return(Json(new { key = true, value = "Model updated successfully" }, JsonRequestBehavior.AllowGet));
                            }
                            else
                            {
                                return(Json(new { key = true, value = "Model not found" }, JsonRequestBehavior.AllowGet));
                            }
                        }
                    };
                }
                else
                {
                    return(Json(new { key = false, value = "Please enter correct data" }, JsonRequestBehavior.AllowGet));
                }
            }
            catch (Exception)
            {
                return(Json(new { key = false, value = "Unable to save the Model" }, JsonRequestBehavior.AllowGet));
            }
        }
        public ActionResult DeleteImage(int imageKey)
        {
            try
            {
                using (MOBILESHOPEntities dbcontext = new MOBILESHOPEntities())
                {
                    var item = dbcontext.mb_device_images.Find(imageKey);
                    if (item != null)
                    {
                        var filePath = "~" + item.image_path;
                        if (System.IO.File.Exists(Server.MapPath(filePath)))
                        {
                            System.IO.File.Delete(Server.MapPath(filePath));
                        }

                        dbcontext.mb_device_images.Remove(item);
                        dbcontext.SaveChanges();
                        return(Json(new { key = true, value = "Image deleted successfully" }, JsonRequestBehavior.AllowGet));
                    }
                    else
                    {
                        return(Json(new { key = false, value = "Image not found" }, JsonRequestBehavior.AllowGet));
                    }
                };
            }
            catch (Exception ex)
            {
                return(Json(new { key = false, value = "Unable to process your request please contact to your admin." }, JsonRequestBehavior.AllowGet));
            }
        }
Пример #5
0
 public ActionResult AddorUpdateService(ServiceDTO dto)
 {
     try
     {
         if (dto.id != 0)
         {
             using (MOBILESHOPEntities dbcontext = new MOBILESHOPEntities())
             {
                 int key     = dto.id;
                 var service = dbcontext.mbshop_service_detail.Find(key);
                 if (service != null)
                 {
                     service.service_name    = dto.serviceName;
                     service.service_charges = dto.serviceCharges;
                     dbcontext.SaveChanges();
                     return(Json(new { key = true, value = "Service updated successfully" }, JsonRequestBehavior.AllowGet));
                 }
                 else
                 {
                     return(Json(new { key = false, value = "service not found" }, JsonRequestBehavior.AllowGet));
                 }
             };
         }
         else
         {
             using (MOBILESHOPEntities dbcontext = new MOBILESHOPEntities())
             {
                 mbshop_service_detail mbservice = new mbshop_service_detail()
                 {
                     service_name    = dto.serviceName,
                     service_charges = dto.serviceCharges
                 };
                 dbcontext.mbshop_service_detail.Add(mbservice);
                 dbcontext.SaveChanges();
                 return(Json(new { key = true, value = "Service added successfully" }, JsonRequestBehavior.AllowGet));
             };
         }
     }
     catch (Exception)
     {
         return(Json(new { key = false, value = "Service is not found" }, JsonRequestBehavior.AllowGet));
     }
 }
Пример #6
0
 public ActionResult AddOrUpdateBrand(BrandDTO dt)
 {
     try
     {
         if (dt.id != 0)
         {
             using (MOBILESHOPEntities dbcontext = new MOBILESHOPEntities())
             {
                 int key   = dt.id;
                 var brand = dbcontext.mb_brand_detail.Find(key);
                 if (brand != null)
                 {
                     brand.brand_name = dt.BrandName;
                     dbcontext.SaveChanges();
                     return(Json(new { key = true, value = "Brand updated successfully" }, JsonRequestBehavior.AllowGet));
                 }
                 else
                 {
                     return(Json(new { key = true, value = "Brand not found" }, JsonRequestBehavior.AllowGet));
                 }
             };
         }
         else
         {
             using (MOBILESHOPEntities dbcontext = new MOBILESHOPEntities())
             {
                 mb_brand_detail mbbrand = new mb_brand_detail()
                 {
                     brand_name = dt.BrandName
                 };
                 dbcontext.mb_brand_detail.Add(mbbrand);
                 dbcontext.SaveChanges();
                 return(Json(new { key = true, value = "Brand added successfully" }, JsonRequestBehavior.AllowGet));
             };
         }
     }
     catch (Exception ex)
     {
         return(Json(new { key = false, value = "Unable to save the Brand" }, JsonRequestBehavior.AllowGet));;
     }
 }
Пример #7
0
 public ActionResult AddOrUpdateFault(FaultDTO dto)
 {
     try
     {
         if (dto.id != 0)
         {
             using (MOBILESHOPEntities dbcontext = new MOBILESHOPEntities())
             {
                 int key   = dto.id;
                 var fault = dbcontext.mb_fault_detail.Find(key);
                 if (fault != null)
                 {
                     fault.fault_name = dto.faultName;
                     dbcontext.SaveChanges();
                     return(Json(new { key = true, value = "Fault updated successfully" }, JsonRequestBehavior.AllowGet));
                 }
                 else
                 {
                     return(Json(new { key = true, value = "Fault not found" }, JsonRequestBehavior.AllowGet));
                 }
             };
         }
         else
         {
             using (MOBILESHOPEntities dbcontext = new MOBILESHOPEntities())
             {
                 mb_fault_detail mbfault = new mb_fault_detail()
                 {
                     fault_name = dto.faultName
                 };
                 dbcontext.mb_fault_detail.Add(mbfault);
                 dbcontext.SaveChanges();
                 return(Json(new { key = true, value = "fault added successfully" }, JsonRequestBehavior.AllowGet));
             };
         }
     }
     catch (Exception)
     {
         return(Json(new { key = false, value = "fault is not found" }, JsonRequestBehavior.AllowGet));
     }
 }
Пример #8
0
 public ActionResult DeleteBrand(int id)
 {
     try
     {
         using (MOBILESHOPEntities dbcontext = new MOBILESHOPEntities())
         {
             var brnd = dbcontext.mb_brand_detail.Find(id);
             if (brnd != null)
             {
                 dbcontext.mb_brand_detail.Remove(brnd);
                 dbcontext.SaveChanges();
                 return(Json(new { key = true, value = "Brand deleted successfully" }, JsonRequestBehavior.AllowGet));
             }
             else
             {
                 return(Json(new { key = false, value = "Brand not Found its Deleted from data base!!" }, JsonRequestBehavior.AllowGet));
             }
         };
     }
     catch (Exception)
     {
         return(Json(new { key = false, value = "Unable to the Brand" }, JsonRequestBehavior.AllowGet));
     }
 }
Пример #9
0
 public ActionResult DeleteService(int id)
 {
     try
     {
         using (MOBILESHOPEntities dbcontext = new MOBILESHOPEntities())
         {
             var service = dbcontext.mbshop_service_detail.Find(id);
             if (service != null)
             {
                 dbcontext.mbshop_service_detail.Remove(service);
                 dbcontext.SaveChanges();
                 return(Json(new { key = true, value = "service deleted successfully" }, JsonRequestBehavior.AllowGet));
             }
             else
             {
                 return(Json(new { key = true, value = "service not Found its Deleted from data base!!" }, JsonRequestBehavior.AllowGet));
             }
         };
     }
     catch (Exception)
     {
         throw;
     }
 }
Пример #10
0
 public ActionResult DeleteFault(int id)
 {
     try
     {
         using (MOBILESHOPEntities dbcontext = new MOBILESHOPEntities())
         {
             var fault = dbcontext.mb_fault_detail.Find(id);
             if (fault != null)
             {
                 dbcontext.mb_fault_detail.Remove(fault);
                 dbcontext.SaveChanges();
                 return(Json(new { key = true, value = "Fault deleted successfully" }, JsonRequestBehavior.AllowGet));
             }
             else
             {
                 return(Json(new { key = false, value = "Fault not Found its Deleted from data base!!" }, JsonRequestBehavior.AllowGet));
             }
         };
     }
     catch (Exception)
     {
         throw;
     }
 }
Пример #11
0
        public ActionResult UploadFiles()
        {
            // Checking no of files injected in Request object
            try
            {
                int    devicekey = Convert.ToInt32(Request.Form["deviceKey"]);
                String paths     = Server.MapPath("~/Uploads"); //Path

                //Check if directory exist
                if (!System.IO.Directory.Exists(paths))
                {
                    Directory.CreateDirectory(paths); //Create directory if it doesn't exist
                }


                Boolean isCapture = Convert.ToBoolean(Request.Form["iscapture"]);

                if (isCapture)
                {
                    string base64image    = Request.Form["CameraImage"].ToString();
                    var    t              = base64image.Substring(23);
                    var    randomFileName = Guid.NewGuid().ToString().Substring(0, 4) + ".png";
                    string imgPath        = Path.Combine(paths, randomFileName);
                    string filePath       = "/Uploads/" + randomFileName;
                    byte[] bytes          = Convert.FromBase64String(t);
                    System.IO.File.WriteAllBytes(imgPath, bytes);
                    using (MOBILESHOPEntities dbcontext = new MOBILESHOPEntities())
                    {
                        mb_device_images images = new mb_device_images()
                        {
                            device_id  = devicekey,
                            image_path = filePath
                        };
                        dbcontext.mb_device_images.Add(images);
                        dbcontext.SaveChanges();
                    };
                }

                if (Request.Files.Count > 0)
                {
                    //  Get all files from Request object
                    HttpFileCollectionBase files = Request.Files;


                    for (int i = 0; i < files.Count; i++)
                    {
                        HttpPostedFileBase file = files[i];
                        string             fname;

                        // Checking for Internet Explorer
                        if (Request.Browser.Browser.ToUpper() == "IE" || Request.Browser.Browser.ToUpper() == "INTERNETEXPLORER")
                        {
                            string[] testfiles = file.FileName.Split(new char[] { '\\' });
                            fname = testfiles[testfiles.Length - 1];
                        }
                        else
                        {
                            fname = Guid.NewGuid() + file.FileName;
                        }
                        string filePath = "/Uploads/" + fname;
                        // Get the complete folder path and store the file inside it.
                        fname = Path.Combine(Server.MapPath("~/Uploads/"), fname);
                        file.SaveAs(fname);

                        using (MOBILESHOPEntities dbcontext = new MOBILESHOPEntities())
                        {
                            mb_device_images images = new mb_device_images()
                            {
                                device_id  = devicekey,
                                image_path = filePath
                            };
                            dbcontext.mb_device_images.Add(images);
                            dbcontext.SaveChanges();
                        };
                    }
                    // Returns message that successfully uploaded
                    return(Json("File Uploaded Successfully!"));
                }
                else
                {
                    return(Json("No files selected."));
                }
            }
            catch (Exception ex)
            {
                return(Json("Error occurred. Error details: " + ex.Message));
            }
        }
Пример #12
0
 public ActionResult AddCustomer(CustomerDTO dto)
 {
     try
     {
         DateTime submitDate  = DateTime.ParseExact(dto.datetime, "MM/dd/yyyy h:mm tt", null);
         DateTime deliverDate = DateTime.ParseExact(dto.datetime, "MM/dd/yyyy h:mm tt", null);
         DateTime?receiveDate = null;
         if (dto.receivedDate != null && dto.receivedDate != "")
         {
             receiveDate = (DateTime.ParseExact(dto.receivedDate, "MM/dd/yyyy h:mm tt", null));
         }
         using (MOBILESHOPEntities dbcontext = new MOBILESHOPEntities())
         {
             if (dto.id == 0)
             {
                 mbshop_customer_details mbshop = new mbshop_customer_details()
                 {
                     customer_name          = dto.Name,
                     customer_address       = dto.Address,
                     customer_email         = dto.Email,
                     customer_mobile_number = dto.Mobile
                 };
                 dbcontext.mbshop_customer_details.Add(mbshop);
                 dbcontext.SaveChanges();
                 int costmerID = mbshop.customer_id;
                 mbshop_device_detail device = new mbshop_device_detail()
                 {
                     device_costumer           = costmerID,
                     device_serial_number      = dto.Serial,
                     device_imei_number_1      = dto.imei_1,
                     device_imei_number_2      = dto.imei_2,
                     device_model_key          = dto.model,
                     device_fault_key          = dto.fault,
                     device_date_submitt       = submitDate,
                     device_description        = dto.Description,
                     device_deliver_date       = deliverDate,
                     device_repairing_cost     = dto.repairingCost,
                     device_customer_signature = dto.customerSignature,
                 };
                 dbcontext.mbshop_device_detail.Add(device);
                 dbcontext.SaveChanges();
                 return(Json(new { key = true, value = "Device Details added successfully", id = device.device_key }, JsonRequestBehavior.AllowGet));
             }
             else
             {
                 var device = dbcontext.mbshop_device_detail.Find(dto.id);
                 if (device != null)
                 {
                     device.device_customer_signature = dto.customerSignature;
                     device.device_date_submitt       = submitDate;
                     device.device_deliver_date       = deliverDate;
                     device.device_description        = dto.Description;
                     device.device_serial_number      = dto.Serial;
                     device.device_imei_number_1      = dto.imei_1;
                     device.device_imei_number_2      = dto.imei_2;
                     device.device_model_key          = dto.model;
                     device.device_fault_key          = dto.fault;
                     device.device_repairing_cost     = dto.repairingCost;
                     device.device_customer_signature = dto.customerSignature;
                     device.device_receiver_signature = dto.receivedSignature;
                     device.device_receiver_name      = dto.receivedName;
                     device.device_receiving_date     = receiveDate;
                     device.device_is_delivered       = dto.deviceDelivered == 1 ? true : false;
                 }
                 dbcontext.SaveChanges();
                 int customerID = device.device_costumer;
                 var customer   = dbcontext.mbshop_customer_details.Find(customerID);
                 if (customer != null)
                 {
                     customer.customer_name          = dto.Name;
                     customer.customer_address       = dto.Address;
                     customer.customer_email         = dto.Email;
                     customer.customer_mobile_number = dto.Mobile;
                     dbcontext.SaveChanges();
                     return(Json(new { key = true, value = "Device Details updated successfully", id = device.device_key }, JsonRequestBehavior.AllowGet));
                 }
                 else
                 {
                     return(Json(new { key = false, value = "Device Details is not found" }, JsonRequestBehavior.AllowGet));
                 }
             }
         };
     }
     catch (Exception ex)
     {
         return(Json(new { key = false, value = "Unable to save the Customer" }, JsonRequestBehavior.AllowGet));;
     }
 }