public async Task <IActionResult> DeleteCar(IdModel carModel) { using (var transaction = _dbContext.Database.BeginTransaction()) { Car carToRemove = _dbContext.Cars.Include(x => x.CarReservations).Where(x => x.Id == Int32.Parse(carModel.Id)).SingleOrDefault(); if (carToRemove != null) { _dbContext.Cars.Remove(carToRemove); _dbContext.SaveChanges(); transaction.Commit(); return(Ok(new { message = "Car is successfully deleted!" })); } return(Ok(new { message = "There is no car with given ID" })); } }
public async Task <Object> AddFriend(IdModel model) { var friend = new Friend { User1 = model.Email, User2 = model.Email2, Type = "Request" }; await Task.Run(() => { _dataBase.Friends.Add(friend); _dataBase.SaveChanges(); }); return(Ok()); }
public ActionResult DeleteConfirmed(int?id) { var articleResponse = new SingularArticleResponse(); var idModel = new IdModel(); idModel.id = id.ToString(); var response = SuperZapatosAPI.CallAPI("services/DeleteArticle/", idModel); if (response.IsSuccessStatusCode) { // Creating Json Request Object articleResponse = new JavaScriptSerializer().Deserialize <SingularArticleResponse>(response.Content.ReadAsStringAsync().Result); } return(RedirectToAction("Index")); }
public async Task <IHttpActionResult> GetAll(IdModel model) { long userId = 0; if (model.Id == null) { userId = long.Parse(User.Identity.GetUserId()); } else { userId = (long)model.Id; } var references = await _referenceRepository.GetByOwnerId(userId); return(SuccessApiResult(references)); }
public async Task <Object> AcceptFriend(IdModel model) { await Task.Run(() => { foreach (Friend f in _dataBase.Friends) { if (f.User1 == model.Email && f.User2 == model.Email2) { f.Type = "Accepted"; } } _dataBase.SaveChanges(); }); return(Ok()); }
public async Task AutoLogin() { JObject jobj = new JObject(); var loginResult = await restmanager.RestRequest <AutoLoginModel>(jobj.ToString(), null, Method.POST, "/autologin"); if (loginResult.result == "1") { IdModel.Get().userId = loginResult.userId; AutoLoginCheck.isValidAccess = true; } else { MessageBox.Show("로그인 만료", "ERROR"); Settings.Default.isALChecked = false; Settings.Default.Save(); } }
public async Task <Result <object> > Remove(IdModel item, bool instantCommit = true) { try { var entity = _routeRepository.GetSingle(item.Id); if (entity != null) { if (await CheckUsersPermission(entity)) { if (await _userResolver.IsConfirmed()) { _routeRepository.Delete(entity); if (instantCommit) { await _routeRepository.Commit(); } return(new Result <object>()); } else { ErrorResult error = GenerateError("User is not confirmed", "", "", ErrorStatus.Forbidden); return(new Result <object>(error)); } } else { ErrorResult error = GenerateError("Action forbidden", "", "", ErrorStatus.Forbidden); return(new Result <object>(error)); } } else { ErrorResult error = GenerateError("Route not found", "Id", "Invalid identifier", ErrorStatus.ObjectNotFound); return(new Result <object>(error)); } } catch (Exception ex) { ErrorResult error = GenerateError(ex); return(new Result <object>(error)); } }
public Task <List <MenuByUserDto> > FindMenuByUser(IdModel request, ServerCallContext context) { return(Task.Run(() => { List <B2B_USER_MENU> userMenuList = base.baseService().FindAll(m => m.USER_ID == request.ID, m => new B2B_USER_MENU { ID = m.ID, MAIN_MENU_ID = m.MAIN_MENU_ID, SUBMENU_ID = m.SUBMENU_ID }).Result; if (userMenuList != null) { return EntityAutoMapper.ConvertMappingList <MenuByUserDto, B2B_USER_MENU>(userMenuList); } return new List <MenuByUserDto>(); })); }
public async Task <IActionResult> GetAllUserCarReservations(IdModel userModel) { User user = new User(); using (var transaction = _dbContext.Database.BeginTransaction()) { user = _dbContext.Users.Include(x => x.RaCCompany).ThenInclude(x => x.Offices).ThenInclude(x => x.Cars).ThenInclude(x => x.CarReservations).Where(x => x.Id == userModel.Id).SingleOrDefault(); transaction.Commit(); } if (user != null) { try { var racCompany = user.RaCCompany as RentACarCompany; if (racCompany != null) { var officesCompany = racCompany.Offices.ToList() as List <Office>; if (officesCompany != null) { List <Office> userOffices = user.RaCCompany.Offices.ToList(); List <CarReservation> retReservations = new List <CarReservation>(); foreach (var office in userOffices) { foreach (var car in office.Cars) { foreach (var carReservation in car.CarReservations) { retReservations.Add(carReservation); } } } return(Ok(new { retReservations })); } } } catch (NullReferenceException nre) { return(Ok(new { retReservations = "Reservation history is empty!" })); } } return(Ok(new { retReservations = "There is no user with this id!" })); }
public dynamic SaveEvents(EventViewModel uM) { IdModel IM = new IdModel(); using (LystenEntities db = new LystenEntities()) { var data = DateTimeOffset.Parse(uM.CreatedDate); if (uM.Id > 0) { Event qs = db.Events.Where(x => x.Id == uM.Id).Include(x => x.Category).FirstOrDefault(); qs.Title = uM.Title; qs.Description = uM.Description; qs.CategoryId = uM.CategoryId; qs.Location = uM.Location; qs.CreatedDate = data.UtcDateTime; qs.Image = uM.Image; qs.IsActive = true; db.Entry(qs).State = EntityState.Modified; db.SaveChanges(); IM.Id = qs.Id; return(IM); } else { Event qs = new Event() { Title = uM.Title, Description = uM.Description, CategoryId = uM.CategoryId, Location = uM.Location, CreatedDate = data.UtcDateTime, Image = uM.Image, CreatorId = uM.UserId, IsActive = true, }; db.Events.Add(qs); db.SaveChanges(); IM.Id = qs.Id; return(IM); } } }
public async Task <IActionResult> CheckInChild(IdModel model) { var user = await userManager.GetUserAsync(User); if (user == null || !(await userManager.IsInRoleAsync(user, UserHelpers.UserRoles.VolunteerCaptain.ToString()) || await userManager.IsInRoleAsync(user, UserHelpers.UserRoles.BusDriver.ToString()) || await userManager.IsInRoleAsync(user, UserHelpers.UserRoles.Staff.ToString()))) { return(Utilities.ErrorJson("Not authorized.")); } if (model == null || model.Id == 0) { return(Utilities.GenerateMissingInputMessage("child id")); } ChildRepository childRepo = new ChildRepository(configModel.ConnectionString); if (childRepo.IsSuspended(model.Id)) { return(new JsonResult(new { Error = "Child is suspended." })); } try { CheckInRepository repo = new CheckInRepository(configModel.ConnectionString); return(new JsonResult(new { NumVisits = repo.CheckInChild(model.Id) })); } catch (Exception exc) { return(new JsonResult(new { Error = exc.Message, })); } }
public async Task <ActionResult> SuspensionHistoryForChild([FromQuery] IdModel model) { var user = await userManager.GetUserAsync(User); if (user == null || !(await userManager.IsInRoleAsync(user, UserHelpers.UserRoles.BusDriver.ToString()) || await userManager.IsInRoleAsync(user, UserHelpers.UserRoles.Staff.ToString()) || await userManager.IsInRoleAsync(user, UserHelpers.UserRoles.VolunteerCaptain.ToString()) || await userManager.IsInRoleAsync(user, UserHelpers.UserRoles.Volunteer.ToString()))) { return(Utilities.ErrorJson("Not authorized.")); } VolunteerRepository volunteerRepo = new VolunteerRepository(configModel.ConnectionString); // Volunteers must be teachers to have access if (User.IsInRole(UserHelpers.UserRoles.Volunteer.ToString()) && !volunteerRepo.VolunteerIsClassTeacher(user.VolunteerId)) { return(Utilities.ErrorJson("Not authorized.")); } if (model == null || model.Id == 0) { return(Utilities.GenerateMissingInputMessage("id")); } try { ChildRepository repo = new ChildRepository(configModel.ConnectionString); return(new JsonResult(new { Suspensions = repo.GetSuspensionHistoryForChild(model) })); } catch (Exception exc) { return(new JsonResult(new { Error = exc.Message, })); } }
public async Task <Result <RouteDetailsViewModel> > GetRouteById(IdModel model) { try { var query = new SearchQuery <RouteInfoEntity>(); RouteInfoEntity result = await _routeRepository.GetSingleWithDependencies(model.Id); if (result == null) { ErrorResult error = GenerateError("Route not found", "Id", "Invalid identifier", ErrorStatus.ObjectNotFound); return(new Result <RouteDetailsViewModel>(error)); } var viewModel = new RouteDetailsViewModel() { Difficulty = result.Difficulty, Id = result.ID, Name = result.Name, UserId = result.UserId, User = new UserListItemModel() { Email = result.User.Email, Id = result.User.ID, Name = result.User.Name, RoutesCount = result.User.Routes.Count }, Geometry = new RouteGeometry() { Id = result.Geometry.ID, Points = GeoPointConverter.GetPoints(result.Geometry.Line), }, MainPoint = GeoPointConverter.GetPoint(result.Point.Point) }; return(new Result <RouteDetailsViewModel>(viewModel)); } catch (Exception ex) { ErrorResult error = GenerateError(ex); return(new Result <RouteDetailsViewModel>(error)); } }
public async Task <IActionResult> GetRacCompanyOffices(IdModel racModel) //Koristimo samo da smjestimo id { RentACarCompany rac = new RentACarCompany(); using (var transaction = _dbContext.Database.BeginTransaction()) { rac = _dbContext.RentACarCompanies.Include(x => x.Offices).Where(x => x.Id == Int32.Parse(racModel.Id)).SingleOrDefault(); transaction.Commit(); } if (rac != null) { List <Office> retOffices = rac.Offices.ToList(); return(Ok(new { retOffices })); } else { return(Ok(new { retOffices = "Rent a Car Company with this id does not exist!" })); } }
public IActionResult Boje(IdModel id) { IdModel idModel = new IdModel { IdPrzycisku = id.IdPrzycisku }; if (idModel.IdPrzycisku == "bo1") { return(View("Boje_1ViewModel")); } else if (idModel.IdPrzycisku == "bo2") { return(View("Boje_2ViewModel")); } else { return(Json(idModel.IdPrzycisku)); } }
public async Task <ShoppingListModel> CreateShoppingListFromTemplate(IdModel templateId, CancellationToken cancellationToken) { var shoppingTemplate = await shoppingTemplateRepository.GetTemplate(templateId, cancellationToken); var shoppingList = new ShoppingListModel { Title = $"{shoppingTemplate.Title} - {clock.UtcNow:yyyy.MM.dd}", Items = shoppingTemplate.Items.Select(x => new ShoppingItemModel { Id = x.Id, Title = x.Title, Quantity = x.Quantity, Comment = x.Comment, }).ToList(), }; await shoppingListRepository.CreateShoppingList(shoppingList, cancellationToken); return(shoppingList); }
public void ParserTest() { long id1 = 1161606687346458624; // 1号协议id long id2 = 2314478978607395428; // 2号协议id for (int i = 0; i < 1000000; i++) { IdModel model1 = IdHelper.Parser(id1); Assert.AreEqual(model1.Sign, 1); Assert.AreEqual(model1.WorkNode, 1); Assert.AreEqual(model1.CreateTime, Convert.ToDateTime("2019/1/10 19:27:07")); Assert.AreEqual(model1.Sequence, 0); IdModel model2 = IdHelper.Parser(id2); Assert.AreEqual(model2.Sign, 2); Assert.AreEqual(model2.WorkNode, 11); Assert.AreEqual(model2.CreateTime, Convert.ToDateTime("2019/1/8 16:31:33")); Assert.AreEqual(model2.Sequence, 612); } Interlocked.Increment(ref finish); }
public void TestCreateFieldWithBuilderAsync() { var request = CreateFieldRequest.Builder() .Resource(ResourceId.Job) .Required(false) .FieldType(FieldType.Date) .DefaultValue(DateTime.Now.ToString("yyyy/MM/dd")) .Searchable(false) .JapaneseLabel("This a date field") .JapaneseCaption("This is a date field"); Task <IdModel> result = session.CallAsync(request.GetRequest()); TestContext.Out.WriteLine("Take a cup of coffee in meantime!"); IdModel response = result.Result; TestContext.Out.WriteLine("Start to get the result !"); Assert.That(response, Is.Not.Null, "Response data is null!"); Assert.That(string.IsNullOrEmpty(response.Id), Is.False, "Id is null!"); TestContext.Out.WriteLine(string.Format("Id: {0}", response.Id)); fieldIdList.Add(response.Id); }
public async Task <Result <object> > Remove(IdModel item) { try { var entity = await _userRepository.GetSingleWithDependencies(item.Id); if (entity != null) { if (await CheckUsersPermission(entity)) { _userRepository.Delete(entity); foreach (RouteInfoEntity route in entity.Routes) { _routeRepository.Delete(route); } } else { ErrorResult error = GenerateError("Action forbidden", "", "", ErrorStatus.Forbidden); return(new Result <object>(error)); } await _userRepository.Commit(); return(new Result <object>()); } else { ErrorResult error = GenerateError("User not found", "Id", "Invalid identifier", ErrorStatus.ObjectNotFound); return(new Result <object>(error)); } } catch (Exception ex) { ErrorResult error = GenerateError(ex); return(new Result <object>(error)); } }
public override int GetHashCode() { int hashCode = IdVer.GetHashCode() + IdSubVer.GetHashCode() + Timestamp.GetHashCode() + (IdPrototype == null ? 0 : IdPrototype.GetHashCode()) + (IdItemBcn == null ? 0 : IdItemBcn.GetHashCode()) + (IdMaterialL1 == null ? 0 : IdMaterialL1.GetHashCode()) + (IdMaterialL2 == null ? 0 : IdMaterialL2.GetHashCode()) + (IdMaterialL3 == null ? 0 : IdMaterialL3.GetHashCode()) + (IdDefaultSupplier == null ? 0 : IdDefaultSupplier.GetHashCode()) + (IdModel == null ? 0 : IdModel.GetHashCode()) + (IdFamilyHK == null ? 0 : IdFamilyHK.GetHashCode()) + Caliber.GetHashCode() + (IdColor1 == null ? 0 : IdColor1.GetHashCode()) + (IdColor2 == null ? 0 : IdColor2.GetHashCode()) + (IdItemHK == null ? 0 : IdItemHK.GetHashCode()) + (ItemDescription == null ? 0 : ItemDescription.GetHashCode()) + (Comments == null ? 0 : Comments.GetHashCode()) + (Segment == null ? 0 : Segment.GetHashCode()) + (Category == null ? 0 : Category.GetHashCode()) + (Age == null ? 0 : Age.GetHashCode()) + (LaunchDate == null ? 0 : LaunchDate.GetHashCode()) + (RemovalDate == null ? 0 : RemovalDate.GetHashCode()) + IdStatusCial.GetHashCode() + IdStatusProd.GetHashCode() + (IdUserAttri1 == null ? 0 : IdUserAttri1.GetHashCode()) + (IdUserAttri2 == null ? 0 : IdUserAttri2.GetHashCode()) + (IdUserAttri3 == null ? 0 : IdUserAttri3.GetHashCode()) + (Unit == null ? 0 : Unit.GetHashCode()) + (DocsLink == null ? 0 : DocsLink.GetHashCode()) + CreateDate.GetHashCode() + User.GetHashCode() + (PhotoUrl == null ? 0 : PhotoUrl.GetHashCode()); return(hashCode); }
public async Task <Object> DeleteFriend(IdModel model) { await Task.Run(() => { foreach (Friend f in _dataBase.Friends) { if (f.User1 == model.Email && f.User2 == model.Email2) { f.Type = "Deleted"; _dataBase.Friends.Remove(f); } else if (f.User2 == model.Email && f.User1 == model.Email2) { f.Type = "Deleted"; _dataBase.Friends.Remove(f); } } _dataBase.SaveChanges(); }); return(Ok()); }
public async Task <Object> GetRequests(IdModel model) { var requests = new List <string>(); var users = new List <User>(); await Task.Run(() => { foreach (Friend f in _dataBase.Friends) { if (f.User2 == model.Email && f.Type == "Request") { requests.Add(f.User1); } } foreach (string s in requests) { var user = _dataBase.Users.SingleOrDefault(u => u.Email == s); users.Add(user); } }); return(Ok(users)); }
public IHttpActionResult Delete(IdModel id) { WareHouseResponse response = new WareHouseResponse(); try { bool success = wareHouseBL.DeleteWareHouse(id.Id); response.Success = success; } catch (WareHouseException ex) { response.ErrorCode = ex.Error; response.ErrorMessage = "Error. " + ex.Error.ToString(); response.WareHouse = null; response.Success = false; } catch (Exception ex) { response.ErrorMessage = "Error. " + ex.Message; response.WareHouse = null; response.Success = false; } return(Ok(response)); }
public IActionResult Automaty(IdModel id) { IdModel idModel = new IdModel { IdPrzycisku = id.IdPrzycisku }; if (idModel.IdPrzycisku == "a1") { return(View("Automaty_1ViewModel")); } else if (idModel.IdPrzycisku == "a2") { return(View("Automaty_2ViewModel")); } else if (idModel.IdPrzycisku == "a3") { return(View("Automaty_3ViewModel")); } else { return(Json(idModel.IdPrzycisku)); } }
public IHttpActionResult Delete(IdModel id) { WeightTicketResponse response = new WeightTicketResponse(); try { bool success = weightTicketsBL.DeleteWeightTicket(id.Id); response.Success = success; } catch (WeightTicketException ex) { response.ErrorCode = ex.Error; response.ErrorMessage = "Error. " + ex.Error.ToString(); response.WeightTicket = null; response.Success = false; } catch (Exception ex) { response.ErrorMessage = "Error. " + ex.Message; response.WeightTicket = null; response.Success = false; } return(Ok(response)); }
public async Task <IActionResult> GetRacCompanyRating(IdModel racModel) //Koristimo samo da smjestimo id { int retVal = 0; RentACarCompany rac = new RentACarCompany(); using (var transaction = _dbContext.Database.BeginTransaction()) { rac = _dbContext.RentACarCompanies.Include(x => x.Offices).ThenInclude(x => x.Cars).ThenInclude(x => x.CarReservations).Where(x => x.Id == Int32.Parse(racModel.Id)).SingleOrDefault(); transaction.Commit(); } if (rac != null) { int rating = 0; int numberOfRatings = 0; foreach (var office in rac.Offices) { foreach (var car in office.Cars) { rating += car.CarRating; numberOfRatings += car.NumberOfRatings; } } if (numberOfRatings != 0) { retVal = rating / numberOfRatings; } return(Ok(new { retVal })); } else { return(Ok(new { retVal = "Rent a Car Company with this id does not exist!" })); } }
public IHttpActionResult Delete(IdModel id) { ProductResponse response = new ProductResponse(); try { bool success = productBL.DeleteProduct(id.Id); response.Success = success; } catch (ProductException ex) { response.ErrorCode = ex.Error; response.ErrorMessage = "Error. " + ex.Error.ToString(); response.Product = null; response.Success = false; } catch (Exception ex) { response.ErrorMessage = "Error. " + ex.Message; response.Product = null; response.Success = false; } return(Ok(response)); }
public IActionResult Kamizelki(IdModel id) { IdModel idModel = new IdModel { IdPrzycisku = id.IdPrzycisku }; if (idModel.IdPrzycisku == "j1") { return(View("Kamizelki_1ViewModel")); } else if (idModel.IdPrzycisku == "j2") { return(View("Kamizelki_2ViewModel")); } else if (idModel.IdPrzycisku == "j3") { return(View("Kamizelki_3ViewModel")); } else { return(Json(idModel.IdPrzycisku)); } }
public IHttpActionResult Delete(IdModel id) { SettlementResponse response = new SettlementResponse(); try { bool success = settlementBL.DeleteSettlement(id.Id); response.Success = success; } catch (SettlementException ex) { response.ErrorCode = ex.Error; response.ErrorMessage = "Error. " + ex.Error.ToString(); response.Settlement = null; response.Success = false; } catch (Exception ex) { response.ErrorMessage = "Error. " + ex.Message; response.Settlement = null; response.Success = false; } return(Ok(response)); }
public IActionResult Skafandry(IdModel id) { IdModel idModel = new IdModel { IdPrzycisku = id.IdPrzycisku }; if (idModel.IdPrzycisku == "s1") { return(View("Skafandry_1ViewModel")); } else if (idModel.IdPrzycisku == "s2") { return(View("Skafandry_2ViewModel")); } else if (idModel.IdPrzycisku == "s3") { return(View("Skafandry_3ViewModel")); } else { return(Json(idModel.IdPrzycisku)); } }