public ActionResult AddCustomer() { CustomerDTO dt = new CustomerDTO(); using (MOBILESHOPEntities dbcontext = new MOBILESHOPEntities()) { dt.brandList = dbcontext.mb_brand_detail.AsEnumerable().Select(x => new BrandDTO { id = x.brand_key, BrandName = x.brand_name }).ToList(); dt.modelList = new List <ModelDTO>();//dt.modelList = dbcontext.mb_model_detail.AsEnumerable().Select(x => new ModelDTO //{ // id = x.model_key, // modelName = x.model_name //}).ToList(); dt.faultList = dbcontext.mb_fault_detail.AsEnumerable().Select(x => new DataTransferObject.Fault.FaultDTO { id = x.fault_key, faultName = x.fault_name }).ToList(); ViewBag.servicesList = dbcontext.mbshop_service_detail.AsEnumerable().Select(x => new DataTransferObject.Services.ServiceDTO { id = x.service_key, serviceName = x.service_name, serviceCharges = x.service_charges, }).ToList(); }; return(View("AddCustomer", dt)); }
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)); } }
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 CustomerListing() { try { List <CostumerListingDto> CstmrList = new List <CostumerListingDto>(); using (MOBILESHOPEntities dbcontext = new MOBILESHOPEntities()) { CustomerDTO dt = new CustomerDTO(); CstmrList = dbcontext.mbshop_device_detail.AsEnumerable().OrderByDescending(x => x.device_key).Select(x => new CostumerListingDto { id = x.device_key, BillNo = x.device_key.ToString(), Name = x.mbshop_customer_details.customer_name, BRAND = x.mb_model_detail.mb_brand_detail.brand_name, MODEL = x.mb_model_detail.model_name, FAULT = x.mb_fault_detail.fault_name, Mobile = x.mbshop_customer_details.customer_mobile_number, isDelivered = x.device_is_delivered == true ? "<h5><span class='badge badge-primary'>Delivered</span></h5>" : "<h5><span class='badge badge-danger'>Not Yet</span></h5>" }).ToList(); }; return(PartialView("_CustomerListing", CstmrList)); } catch (Exception ex) { throw; } }
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)); } }
public ActionResult UpdateBrand(int id) { BrandDTO dt = new BrandDTO(); using (MOBILESHOPEntities dbcontext = new MOBILESHOPEntities()) { var brand = dbcontext.mb_brand_detail.Find(id); dt.id = brand.brand_key; dt.BrandName = brand.brand_name; }; return(PartialView("AddBrand", dt)); }
public ActionResult UpdateFault(int id) { FaultDTO dt = new FaultDTO(); using (MOBILESHOPEntities dbcontext = new MOBILESHOPEntities()) { var fault = dbcontext.mb_fault_detail.Find(id); dt.id = fault.fault_key; dt.faultName = fault.fault_name; }; return(PartialView("AddFault", dt)); }
public ActionResult BrandListing() { List <BrandDTO> brandlist = new List <BrandDTO>(); using (MOBILESHOPEntities dbcontext = new MOBILESHOPEntities()) { brandlist = dbcontext.mb_brand_detail.AsEnumerable().OrderByDescending(x => x.brand_key).Select(x => new BrandDTO { id = x.brand_key, BrandName = x.brand_name }).ToList(); }; return(PartialView("BrandListing", brandlist)); }
public ActionResult AddModel() { ModelDTO dt = new ModelDTO(); using (MOBILESHOPEntities dbcontext = new MOBILESHOPEntities()) { //Brand dt.brandList = dbcontext.mb_brand_detail.AsEnumerable().Select(x => new BrandDTO { id = x.brand_key, BrandName = x.brand_name }).ToList(); }; return(PartialView("AddModel", dt)); }
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 UpdateModel(int id) { ModelDTO dt = new ModelDTO(); using (MOBILESHOPEntities dbcontext = new MOBILESHOPEntities()) { var model = dbcontext.mb_model_detail.Find(id); dt.id = model.model_key; dt.modelName = model.model_name; dt.Brand = model.model_brand_key; dt.brandList = dbcontext.mb_brand_detail.AsEnumerable().Select(x => new BrandDTO { id = x.brand_key, BrandName = x.brand_name }).ToList(); }; return(PartialView("AddModel", dt)); }
public ActionResult GetModels(int brandkey) { try { using (MOBILESHOPEntities dbcontext = new MOBILESHOPEntities()) { var list = dbcontext.mb_model_detail.Where(x => x.model_brand_key == brandkey).AsEnumerable().Select(x => new ModelDTO { modelName = x.model_name, id = x.model_key }).ToList(); return(Json(new { key = true, value = list }, JsonRequestBehavior.AllowGet)); }; } catch (Exception ex) { return(Json(new { key = false, value = "" }, JsonRequestBehavior.AllowGet)); } }
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)); } }
public ActionResult EditService(int id) { try { ServiceDTO dto = new ServiceDTO(); using (MOBILESHOPEntities dbcontext = new MOBILESHOPEntities()) { var service = dbcontext.mbshop_service_detail.Find(id); dto.id = service.service_key; dto.serviceName = service.service_name; dto.serviceCharges = service.service_charges; }; return(PartialView("AddService", dto)); } catch (Exception) { throw; } }
public ActionResult FaultListing() { try { List <FaultDTO> faultList = new List <FaultDTO>(); using (MOBILESHOPEntities dbcontext = new MOBILESHOPEntities()) { faultList = dbcontext.mb_fault_detail.AsEnumerable().OrderByDescending(x => x.fault_key).Select(x => new FaultDTO { id = x.fault_key, faultName = x.fault_name }).ToList(); }; return(PartialView("_FaultListing", faultList)); } catch (Exception) { throw; } }
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));; } }
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)); } }
public ActionResult ModelListing() { try { List <ModelDTO> modelList = new List <ModelDTO>(); using (MOBILESHOPEntities dbcontext = new MOBILESHOPEntities()) { modelList = dbcontext.mb_model_detail.AsEnumerable().OrderByDescending(x => x.model_key).Select(x => new ModelDTO { id = x.model_key, modelName = x.model_name, BrandName = x.mb_brand_detail.brand_name }).ToList(); return(PartialView("ModelListing", modelList)); }; } catch (Exception) { throw; } }
public ActionResult ServiceListing() { try { List <ServiceDTO> serviceList = new List <ServiceDTO>(); using (MOBILESHOPEntities dbcontext = new MOBILESHOPEntities()) { serviceList = dbcontext.mbshop_service_detail.AsEnumerable().OrderByDescending(x => x.service_key).Select(x => new ServiceDTO { id = x.service_key, serviceName = x.service_name, serviceCharges = x.service_charges }).ToList(); }; return(PartialView("_ServiceListing", serviceList)); } catch (Exception) { return(Json(new { key = false, value = "Service is not found" }, JsonRequestBehavior.AllowGet)); } }
public ActionResult GeneratePdf(int id) { string pdfName = Guid.NewGuid().ToString(); Customer_Device_ServicesDTO dto = new Customer_Device_ServicesDTO(); using (MOBILESHOPEntities dbcontext = new MOBILESHOPEntities()) { var cstmr = dbcontext.mbshop_device_detail.Find(id); if (cstmr != null) { dto.RefNo = cstmr.device_key.ToString(); dto.customerName = cstmr.mbshop_customer_details.customer_name; dto.Address = cstmr.mbshop_customer_details.customer_address; dto.Email = cstmr.mbshop_customer_details.customer_email; dto.PhonNumber = cstmr.mbshop_customer_details.customer_mobile_number; dto.Imei_1 = cstmr.device_imei_number_1; dto.Imei_2 = cstmr.device_imei_number_2; dto.Brand = cstmr.mb_model_detail.mb_brand_detail.brand_name; dto.Model = cstmr.mb_model_detail.model_name; dto.Fault = cstmr.mb_fault_detail.fault_name; dto.SubmittDate = cstmr.device_date_submitt.ToString("MM/dd/yyyy h:mm tt"); dto.RepairingCost = cstmr.device_repairing_cost; dto.DeliverDate = Convert.ToDateTime(cstmr.device_deliver_date).ToString("MM/dd/yyyy h:mm tt"); dto.CustomerSignature = cstmr.device_customer_signature != null ? cstmr.device_customer_signature : "~/images/300px-No_image_available.svg (1).png"; } int i = 1; dto.services = dbcontext.Costumer_Device_Services.Where(x => x.cds_device_key == id).AsEnumerable().Select(x => new ServiceDTO { id = (i++), serviceName = x.mbshop_service_detail.service_name, serviceCharges = x.mbshop_service_detail.service_charges }).ToList(); }; return(new ViewAsPdf("CustomerBillPdf", dto) { FileName = pdfName + ".pdf" }); }
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)); } }
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; } }
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; } }
public ActionResult EmailBill(int id) { try { string pdfName = Guid.NewGuid().ToString() + ".pdf"; Customer_Device_ServicesDTO dto = new Customer_Device_ServicesDTO(); using (MOBILESHOPEntities dbcontext = new MOBILESHOPEntities()) { var cstmr = dbcontext.mbshop_device_detail.Find(id); if (cstmr != null) { dto.RefNo = cstmr.device_key.ToString(); dto.customerName = cstmr.mbshop_customer_details.customer_name; dto.Address = cstmr.mbshop_customer_details.customer_address; dto.Email = cstmr.mbshop_customer_details.customer_email; dto.PhonNumber = cstmr.mbshop_customer_details.customer_mobile_number; dto.Imei_1 = cstmr.device_imei_number_1; dto.Imei_2 = cstmr.device_imei_number_2; dto.Brand = cstmr.mb_model_detail.mb_brand_detail.brand_name; dto.Model = cstmr.mb_model_detail.model_name; dto.Fault = cstmr.mb_fault_detail.fault_name; dto.SubmittDate = cstmr.device_date_submitt.ToString("MM/dd/yyyy h:mm tt"); dto.RepairingCost = cstmr.device_repairing_cost; dto.DeliverDate = Convert.ToDateTime(cstmr.device_deliver_date).ToString("MM/dd/yyyy h:mm tt"); dto.CustomerSignature = cstmr.device_customer_signature != null ? cstmr.device_customer_signature : "~/images/300px-No_image_available.svg (1).png"; } int i = 1; dto.services = dbcontext.Costumer_Device_Services.Where(x => x.cds_device_key == id).AsEnumerable().Select(x => new ServiceDTO { id = (i++), serviceName = x.mbshop_service_detail.service_name, serviceCharges = x.mbshop_service_detail.service_charges }).ToList(); }; string virtualpath = "~/PdfBills/" + pdfName; var root = Server.MapPath("~/PdfBills/"); var path = Path.Combine(root, pdfName); path = Path.GetFullPath(path); var pdfPath = new ViewAsPdf("CustomerBillPdf", dto) { FileName = pdfName, }; var byteArray = pdfPath.BuildPdf(ControllerContext); Stream stream = new MemoryStream(byteArray); System.Net.Mime.ContentType ct = new System.Net.Mime.ContentType(System.Net.Mime.MediaTypeNames.Text.Html); System.Net.Mail.Attachment attach = new System.Net.Mail.Attachment(stream, ct); attach.ContentDisposition.FileName = pdfName; //send Email SmtpClient client = new SmtpClient(); MailMessage email = new MailMessage(); email.From = new MailAddress("*****@*****.**"); email.To.Add(dto.Email); email.Subject = "Bill from Bariq Mobile"; email.Body = ""; email.Attachments.Add(attach); client.Send(email); return(Json(new { key = true, value = "Email sent Successfully" }, JsonRequestBehavior.AllowGet)); } catch (Exception ex) { return(Json(new { key = true, value = "Email sending Failed - Please try again" }, JsonRequestBehavior.AllowGet)); } }
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));; } }
public ActionResult EditCostumer(int id) { using (MOBILESHOPEntities dbcontext = new MOBILESHOPEntities()) { var row = dbcontext.mbshop_device_detail.Find(id); CustomerDTO dto = new CustomerDTO() { id = row.device_key, Address = row.mbshop_customer_details.customer_address, Email = row.mbshop_customer_details.customer_email, Mobile = row.mbshop_customer_details.customer_mobile_number, Name = row.mbshop_customer_details.customer_name, Brand = row.mb_model_detail.mb_brand_detail.brand_key, model = row.device_model_key, datetime = row.device_date_submitt.ToString("MM/dd/yyyy h:mm tt"), Description = row.device_description, fault = row.device_fault_key, Serial = row.device_serial_number, imei_1 = row.device_imei_number_1, imei_2 = row.device_imei_number_2, customerSignature = row.device_customer_signature != null ? row.device_customer_signature : "/images/300px-No_image_available.svg (1).png", deliverDate = Convert.ToDateTime(row.device_deliver_date).ToString("MM/dd/yyyy h:mm tt"), repairingCost = row.device_repairing_cost, receivedSignature = row.device_receiver_signature != null ? row.device_receiver_signature : "/images/300px-No_image_available.svg (1).png", receivedDate = row.device_receiving_date != null?Convert.ToDateTime(row.device_receiving_date).ToString("MM/dd/yyyy h:mm tt") : DateTime.Now.ToString("MM/dd/yyyy h:mm tt"), receivedName = row.device_receiver_name, deviceDelivered = row.device_is_delivered == true ? 1 : 0 }; dto.brandList = dbcontext.mb_brand_detail.AsEnumerable().Select(x => new BrandDTO { id = x.brand_key, BrandName = x.brand_name }).ToList(); dto.modelList = dbcontext.mb_model_detail.AsEnumerable().Select(x => new ModelDTO { id = x.model_key, modelName = x.model_name }).ToList(); dto.faultList = dbcontext.mb_fault_detail.AsEnumerable().Select(x => new DataTransferObject.Fault.FaultDTO { id = x.fault_key, faultName = x.fault_name }).ToList(); ViewBag.images = dbcontext.mb_device_images.Where(d => d.device_id == id).AsEnumerable().Select(d => new DeviceImagesDTO { Id = d.image_key, path = d.image_path }).ToList(); ViewBag.servicesList = dbcontext.mbshop_service_detail.AsEnumerable().Select(x => new DataTransferObject.Services.ServiceDTO { id = x.service_key, serviceName = x.service_name, serviceCharges = x.service_charges, }).ToList(); ViewBag.selected_servicesList = dbcontext.Costumer_Device_Services.Where(x => x.cds_device_key == id).AsEnumerable().Select(x => new DataTransferObject.Services.ServiceDTO { id = x.mbshop_service_detail.service_key, serviceName = x.mbshop_service_detail.service_name, serviceCharges = x.mbshop_service_detail.service_charges, }).ToList(); return(View("EditCostumer", dto)); }; }
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)); } }