public ActionResult Details(string id) { var model = new LocationUpdateModel(); var locations = LocationBlo.GetLocations2(AppDomain.CurrentDomain.BaseDirectory); var exists = locations.Where(x => x.Id == id).ToList(); if (exists.Count > 0) { var item = exists[0]; model = new LocationUpdateModel { Id = item.Id, Name = item.Name, Address = item.Address, PhoneNumbers = item.PhoneNumbers, FaxNumbers = item.FaxNumbers, LocationType = item.LocationType, Specialists = LocationDto.SpecialistsToString(item.Specialists), Rating = item.Rating.ToString(CultureInfo.CurrentCulture), Area1 = item.Area1, Area2 = item.Area2, Latitude = item.Latitude, Longitude = item.Longitude }; } return(View(model)); }
public ActionResult GetLocations() { List <LocationUpdateModel> models = new List <LocationUpdateModel>(); var locations = LocationBlo.GetLocations2(AppDomain.CurrentDomain.BaseDirectory); foreach (var item in locations) { var location = new LocationUpdateModel { Id = item.Id, Name = item.Name, Address = item.Address, PhoneNumbers = item.PhoneNumbers, FaxNumbers = item.FaxNumbers, LocationType = item.LocationType, Specialists = LocationDto.SpecialistsToString(item.Specialists), Rating = item.Rating.ToString(CultureInfo.CurrentCulture), Area1 = item.Area1, Area2 = item.Area2, Latitude = item.Latitude, Longitude = item.Longitude }; models.Add(location); } return(View(models)); }
public async Task <IActionResult> UpdateAsync(int id, [FromBody] LocationUpdateModel mLocation) { if (!ModelState.IsValid) { return(HttpBadRequest(ModelStateError())); } var locationId = await _locationRepository.UpdateByIdAsync(id, mLocation); return(CreatedAtRoute("GetByLocationIdAsync", new { controller = "Locations", locationId = locationId }, mLocation)); }
public ActionResult Create(LocationUpdateModel model) { if (model == null) { model = new LocationUpdateModel(); } else { if (!string.IsNullOrEmpty(model.Name)) { var item = model; var location = new LocationDto { Id = item.Id, Name = item.Name, Address = item.Address, PhoneNumbers = item.PhoneNumbers, FaxNumbers = item.FaxNumbers, LocationType = item.LocationType, Specialists = LocationDto.ParseSpecialists(item.Specialists), Rating = 0, Area1 = item.Area1, Area2 = item.Area2, Latitude = item.Latitude, Longitude = item.Longitude }; double temp; if (double.TryParse(item.Rating, out temp)) { location.Rating = temp; } LocationBlo.Add(AppDomain.CurrentDomain.BaseDirectory, location); } } return(View(model)); }
public IActionResult ApiEdit(LocationUpdateModel model) { if (!ModelState.IsValid) { return(Ok(ServiceResult.Error(ModelState))); } // update location var location = _repo.Find(model.Id); if (location == null) { return(Ok(ServiceResult.Error("شناسه ارسال شده فاقد اعتبار است"))); } location.Title = model.Title; var updateResult = _repo.Update(location); // update manager of location var manager = _repo.AsQueryable <LocationMember>() .Where(c => c.Type == MemberType.Manager && c.LocationId == model.Id) .FirstOrDefault(); if (manager != null) { _repo.Delete <LocationMember>(manager); } _repo.Create <LocationMember>(new LocationMember() { FullName = model.ManagerFullName, LocationId = model.Id, Type = MemberType.Manager, PhoneNumbers = JsonConvert.SerializeObject(model.ManagerPhoneNumbers) }); return(Ok(ServiceResult.Okay())); }
public async Task FullTest() { var mediator = ServiceProvider.GetService <IMediator>(); mediator.Should().NotBeNull(); var createModel = new LocationCreateModel { Name = "Location " + DateTime.Now.Ticks, Description = "Created from Unit Test", TenantId = Data.Constants.Tenant.Test }; var createCommand = new EntityCreateCommand <LocationCreateModel, LocationReadModel>(MockPrincipal.Default, createModel); var createResult = await mediator.Send(createCommand).ConfigureAwait(false); createResult.Should().NotBeNull(); var identifierQuery = new EntityIdentifierQuery <Guid, LocationReadModel>(MockPrincipal.Default, createResult.Id); var identifierResult = await mediator.Send(identifierQuery).ConfigureAwait(false); identifierResult.Should().NotBeNull(); identifierResult.Name.Should().Be(createModel.Name); var entityQuery = new EntityQuery { Sort = new List <EntitySort> { new EntitySort { Name = "Updated", Direction = "Descending" } }, Filter = new EntityFilter { Name = "Name", Value = "Location", Operator = "StartsWith" } }; var listQuery = new EntityPagedQuery <LocationReadModel>(MockPrincipal.Default, entityQuery); var listResult = await mediator.Send(listQuery).ConfigureAwait(false); listResult.Should().NotBeNull(); var patchModel = new JsonPatchDocument <Location>(); patchModel.Operations.Add(new Operation <Location> { op = "replace", path = "/Description", value = "Patch Update" }); var patchCommand = new EntityPatchCommand <Guid, LocationReadModel>(MockPrincipal.Default, createResult.Id, patchModel); var patchResult = await mediator.Send(patchCommand).ConfigureAwait(false); patchResult.Should().NotBeNull(); patchResult.Description.Should().Be("Patch Update"); var updateModel = new LocationUpdateModel { Name = patchResult.Name, Description = "Update Command", TenantId = patchResult.TenantId, RowVersion = patchResult.RowVersion }; var updateCommand = new EntityUpdateCommand <Guid, LocationUpdateModel, LocationReadModel>(MockPrincipal.Default, createResult.Id, updateModel); var updateResult = await mediator.Send(updateCommand).ConfigureAwait(false); updateResult.Should().NotBeNull(); updateResult.Description.Should().Be("Update Command"); var deleteCommand = new EntityDeleteCommand <Guid, LocationReadModel>(MockPrincipal.Default, createResult.Id); var deleteResult = await mediator.Send(deleteCommand).ConfigureAwait(false); deleteResult.Should().NotBeNull(); deleteResult.Id.Should().Be(createResult.Id); }
public ActionResult Edit(LocationUpdateModel model, string id) { if (model == null) { model = new LocationUpdateModel(); } if (!string.IsNullOrEmpty(id)) { var locations = LocationBlo.GetLocations2(AppDomain.CurrentDomain.BaseDirectory); var exists = locations.Where(x => x.Id == id).ToList(); if (exists.Count > 0) { var item = exists[0]; model = new LocationUpdateModel { Id = item.Id, Name = item.Name, Address = item.Address, PhoneNumbers = item.PhoneNumbers, FaxNumbers = item.FaxNumbers, LocationType = item.LocationType, Specialists = LocationDto.SpecialistsToString(item.Specialists), Rating = item.Rating.ToString(CultureInfo.CurrentCulture), Area1 = item.Area1, Area2 = item.Area2, Latitude = item.Latitude, Longitude = item.Longitude }; } } else { if (!string.IsNullOrEmpty(model.Name)) { var item = model; var location = new LocationDto { Id = item.Id, Name = item.Name, Address = item.Address, PhoneNumbers = item.PhoneNumbers, FaxNumbers = item.FaxNumbers, LocationType = item.LocationType, Specialists = LocationDto.ParseSpecialists(item.Specialists), Rating = 0, Area1 = item.Area1, Area2 = item.Area2, Latitude = item.Latitude, Longitude = item.Longitude }; double temp; if (double.TryParse(item.Rating, out temp)) { location.Rating = temp; } LocationBlo.Update(AppDomain.CurrentDomain.BaseDirectory, location); } } return(View(model)); }
public async Task <int> UpdateByIdAsync(int locationId, LocationUpdateModel mLocation) { var location = _context.Locations.FirstOrDefault(l => l.LocationId == locationId); if (location == null) { throw new ExpectException("Could not find data which DeviceLocation equal to " + locationId); } var device = _context.Devices.FirstOrDefault(l => l.DeviceId == mLocation.DeviceId); if (device == null) { throw new ExpectException("Could not find Device data which DeviceId equal to " + mLocation.DeviceId); } //InstallationNumber must be unique var checkData = await _context.Locations .Where(dl => dl.InstallationNumber == mLocation.InstallationNumber && dl.LocationId != locationId).ToListAsync(); if (checkData.Count > 0) { throw new ExpectException("The data which InstallationNumber equal to '" + mLocation.InstallationNumber + "' already exist in system"); } //DeviceSerialNo must be unique checkData = await _context.Locations .Where(dl => dl.DeviceSerialNo == mLocation.DeviceSerialNo && dl.LocationId != locationId).ToListAsync(); if (checkData.Count > 0) { throw new ExpectException("The data which DeviceSerialNo equal to '" + mLocation.DeviceSerialNo + "' already exist in system"); } //Check Orientation if (!Enum.IsDefined(typeof(Orientation), mLocation.Orientation)) { throw new ExpectException("Invalid Orientation.You can get correct Orientation values from API"); } //Check DeviceType if (!Enum.IsDefined(typeof(DeviceType), mLocation.DeviceType)) { throw new ExpectException("Invalid DeviceType.You can get correct DeviceType values from API"); } //Check CommMode if (!Enum.IsDefined(typeof(CommMode), mLocation.CommMode)) { throw new ExpectException("Invalid CommMode.You can get correct CommMode values from API"); } //Get UserInfo var user = _loginUser.GetLoginUserInfo(); location.Building = mLocation.Building; location.CommAddress = mLocation.CommAddress; location.CommMode = mLocation.CommMode; location.CurrentPosition = mLocation.CurrentPosition; location.Description = mLocation.Description; location.DeviceSerialNo = mLocation.DeviceSerialNo; location.DeviceId = mLocation.DeviceId; location.DeviceType = mLocation.DeviceType; location.FavorPositionFirst = mLocation.FavorPositionFirst; location.FavorPositionrSecond = mLocation.FavorPositionrSecond; location.FavorPositionThird = mLocation.FavorPositionThird; location.Floor = mLocation.Floor; location.InstallationNumber = mLocation.InstallationNumber; location.Orientation = mLocation.Orientation; location.RoomNo = mLocation.RoomNo; location.Modifier = user.UserName; location.ModifiedDate = DateTime.Now; await _context.SaveChangesAsync(); return(location.LocationId); }
public async Task <IActionResult> UpdateLocation([FromRoute] string username, [FromBody] LocationUpdateModel locationUpdateModel) { await positionService.SavePosition(locationUpdateModel.Latitude, locationUpdateModel.Longitude, locationUpdateModel.Altitude, username).ConfigureAwait(false); var connectionIds = positionHubService.GetConnectionIdsRelatedTo(username); await positionHub.Clients.Clients(connectionIds).SendAsync(Methods.UPDATELOCATION, username, locationUpdateModel.Latitude, locationUpdateModel.Longitude, locationUpdateModel.Altitude).ConfigureAwait(false); return(Ok()); }