public ActionResult WorkplaceInMapAndroid(WorkplaceGps vm) { using (var db = new EngineContext()) { // دسترسی موبایلی if (!Request.IsAuthenticated) { string username = SecurityService.GetUsernameFromToken(vm.token); //یافتن پرسنل var workplacePersonnel = db.WorkplacePersonnels.FirstOrDefault(p => p.Username == username); if (workplacePersonnel == null) { throw new Exception("کاربر یافت نشد"); } if (workplacePersonnel.WorkplaceId != vm.WorkplaceId) { throw new Exception("شما به این شرکت دسترسی ندارید"); } } } return(WorkplaceInMap(vm)); }
public ActionResult WorkplaceInMap(WorkplaceGps vm) { try { if (vm.WorkplaceId == 0) { throw new Exception("محل کار ارسال نشده است"); } using (var db = new EngineContext()) { // دسترسی موبایلی if (!Request.IsAuthenticated) { string username = SecurityService.GetUsernameFromToken(vm.token); //یافتن پرسنل var workplacePersonnel = db.WorkplacePersonnels.FirstOrDefault(p => p.Username == username); if (workplacePersonnel == null) { throw new Exception("کاربر یافت نشد"); } if (workplacePersonnel.WorkplaceId != vm.WorkplaceId) { throw new Exception("شما به این شرکت دسترسی ندارید"); } } var workplace = db.Workplaces.Find(vm.WorkplaceId); if (workplace == null) { throw new Exception("محل کار موجود نیست"); } WorkplaceGps gps = null; workplace.Gps = JsonConvert.SerializeObject(vm); workplace.Name = vm.Name; db.Entry(workplace).State = EntityState.Modified; ViewData["id"] = workplace.Id; ViewData["name"] = workplace.Name; ViewData["gps"] = workplace.Gps; db.SaveChanges(); } } catch (Exception e) { Response.StatusCode = (int)HttpStatusCode.InternalServerError; GenErrorMessage(ViewData, e.Message); } return(Json(vm.WorkplaceId, JsonRequestBehavior.AllowGet)); }