public ActionResult Edit(long id, Entities.Beacon beacon) { JsonResponse response = new JsonResponse(); response.Message = ConstantUtil.MessageError; response.Status = ConstantUtil.StatusFail; if (ModelState.IsValid) { try { var newBeacon = _unitOfWorkAsync.Repository <Entities.Beacon>().Find(beacon.Id); newBeacon.ModifiedBy = CurrentUser; newBeacon.ModifiedDate = DateTime.UtcNow; newBeacon.CompanyID = CurrentCompany.CompanyId; newBeacon.BeaconName = beacon.BeaconName; newBeacon.Description = beacon.Description; newBeacon.Active = beacon.Active; _unitOfWorkAsync.Repository <Entities.Beacon>().Update(newBeacon); var success = _unitOfWorkAsync.SaveChanges() > 0; if (success) { response.Message = "Beacon updated successfully."; response.Status = ConstantUtil.StatusOk; response.ReturnUrl = Url.Action("Index"); } } catch (Exception ex) { logging.Error(ex.ToString()); } } return(Json(response, JsonRequestBehavior.AllowGet)); }
public ActionResult Create(Entities.Beacon beacon) { JsonResponse response = new JsonResponse(); response.Message = ConstantUtil.MessageError; response.Status = ConstantUtil.StatusFail; if (ModelState.IsValid) { try { beacon.Active = true; beacon.CreatedBy = CurrentUser; beacon.CreatedDate = DateTime.UtcNow; beacon.CompanyID = CurrentCompany.CompanyId; var existingBeacon = _unitOfWorkAsync.Repository <Entities.Beacon>().GetByBeaconNum(beacon.BeaconID); if (existingBeacon == null) { _unitOfWorkAsync.Repository <Entities.Beacon>().Insert(beacon); var success = _unitOfWorkAsync.SaveChanges() > 0; if (success) { response.Message = "Beacon created successfully."; response.Status = ConstantUtil.StatusOk; response.ReturnUrl = Url.Action("Index"); } } else { response.Message = "Beacon already exist."; } } catch (Exception ex) { logging.Error(ex.ToString()); } } return(Json(response, JsonRequestBehavior.AllowGet)); }
public ActionResult Upload(HttpPostedFileBase file) { var beacon = new Entities.Beacon(); JsonResponse response = new JsonResponse(); if (file == null) { ViewBag.AlertMessage = "Please select a .csv File"; } else { //TO:DO var fileName = Path.GetFileName(file.FileName); var path = Path.Combine(Server.MapPath("~/Content/Upload"), fileName); file.SaveAs(path); ModelState.Clear(); ViewBag.Message = "File uploaded successfully"; using (LiveKart.Business.CSV.ReadWriteCSV.CsvFileReader reader = new ReadWriteCSV.CsvFileReader(path)) { LiveKart.Business.CSV.ReadWriteCSV.CsvRow row = new LiveKart.Business.CSV.ReadWriteCSV.CsvRow(); long count = 0; long dcount = 0; long ccount = 0; while (reader.ReadRow(row)) { beacon.BeaconID = row[0].ToString(); beacon.BeaconName = row[1].ToString(); beacon.Description = row[2].ToString(); beacon.Active = true; beacon.CreatedBy = CurrentUser; beacon.CreatedDate = DateTime.UtcNow; beacon.CompanyID = CurrentCompany.CompanyId; var existingBeacon = _unitOfWorkAsync.Repository <Entities.Beacon>().GetByBeaconNum(beacon.BeaconID); if (existingBeacon == null) { _unitOfWorkAsync.Repository <Entities.Beacon>().Insert(beacon); var success = _unitOfWorkAsync.SaveChanges() > 0; if (success) { count = count + 1; } else { dcount = dcount + 1; } } else { ccount = ccount + 1; } } if (dcount == 0 && count > 0 && ccount == 0) { ViewBag.AlertMessage = " Beacons created sucessfully."; } else if (count > 0 && dcount > 0 && ccount == 0) { ViewBag.AlertMessage = count + " Beacons created sucessfully and " + dcount + " Beacons not created."; } else if (count > 0 && dcount > 0 && ccount > 0) { ViewBag.AlertMessage = count + " Beacons created sucessfully , " + dcount + " Beacons not created. and " + ccount + " beacons already exists."; } else if (count > 0 && dcount == 0 && ccount > 0) { ViewBag.AlertMessage = count + " Beacons created sucessfully and " + ccount + " beacons already exists."; } else if (count == 0 && dcount == 0 && ccount > 0) { ViewBag.AlertMessage = "Beacons already Exists"; } } } return(View()); }