public RoleDto GetRole(string roleId) { IdentityRole role; try { role = _rolesBusinessLogic.GetRole(roleId); } catch (ArgumentException ex) { this.Log.Error(LogHelper.GetMethodInfoErrorMessage(MethodBase.GetCurrentMethod(), roleId), ex); var fault = new EntityNotFoundFault { Message = "Role not found", EntityName = typeof(IdentityRole).Name }; throw new FaultException <EntityNotFoundFault>(fault); } RoleDto roleDto = Mapper.Map <RoleDto>(role); return(roleDto); }
public RoleDto[] GetUserRoles(string userId) { List <IdentityRole> roles; try { roles = _userBusinessLogic.GetUserRoles(userId); } catch (ArgumentException ex) { this.Log.Error(LogHelper.GetMethodInfoErrorMessage(MethodBase.GetCurrentMethod(), userId), ex); var fault = new EntityNotFoundFault { Message = "User not found", EntityName = typeof(ApplicationUser).Name }; throw new FaultException <EntityNotFoundFault>(fault); } RoleDto[] rolesDto = Mapper.Map <RoleDto[]>(roles); return(rolesDto); }
public UserDto GetUser(string userId) { ApplicationUser user; try { user = _userBusinessLogic.GetUser(userId); } catch (ArgumentException ex) { this.Log.Error(LogHelper.GetMethodInfoErrorMessage(MethodBase.GetCurrentMethod(), userId), ex); var fault = new EntityNotFoundFault { Message = "User not found", EntityName = typeof(User).Name }; throw new FaultException <EntityNotFoundFault>(fault); } UserDto userDto = Mapper.Map <UserDto>(user); return(userDto); }
public RobotProgramDto GetProgram(Guid id) { RobotProgram robotProgram; try { robotProgram = _robotProgramBusinessLogic.GetProgram(id); } catch (ArgumentException ex) { this.Log.Error(LogHelper.GetMethodInfoErrorMessage(MethodBase.GetCurrentMethod(), id), ex); var fault = new EntityNotFoundFault { Message = "Robot program not found", EntityName = typeof(RobotProgram).Name }; throw new FaultException <EntityNotFoundFault>(fault); } RobotProgramDto programDto = Mapper.Map <RobotProgramDto>(robotProgram); return(programDto); }
public ProgramStepDto GetStep(Guid id) { ProgramStep programStep; try { programStep = _robotProgramBusinessLogic.GetStep(id); } catch (ArgumentException ex) { this.Log.Error(LogHelper.GetMethodInfoErrorMessage(MethodBase.GetCurrentMethod(), id), ex); var fault = new EntityNotFoundFault { Message = "Step program not found", EntityName = typeof(ProgramStep).Name }; throw new FaultException <EntityNotFoundFault>(fault); } ProgramStepDto stepDto = Mapper.Map <ProgramStepDto>(programStep); return(stepDto); }
/// <summary> /// Method that gets customer object with given id. /// </summary> /// <param name="customerId">Id of customer to get data on.</param> /// <returns>Customer object representing customer data in db for given customerid.</returns> public Customer GetCustomer(int customerId) { int i; Customer c = repos.FindBy <Customer>(customer => customer.Id == customerId).FirstOrDefault(); if (null == c || (int.TryParse(c.Id.ToString(), out i) == false)) { EntityNotFoundFault fault = new EntityNotFoundFault(); fault.Message = "Error trying to retrieve customer data."; fault.Description = "No Customer with given Id in database."; throw new FaultException <EntityNotFoundFault>(fault); } else { return(c); } }
/// <summary> /// Get car from database based on given id. /// </summary> /// <param name="carId">Id of car to get data on.</param> /// <returns>If found in db- the car object, else- throw exception.</returns> public Car GetCar(int carId) { int i = 0; Car car = repos.FindBy <Car>(c => c.Id == carId).FirstOrDefault(); if (null == car || int.TryParse(car.Id.ToString(), out i) == false) { EntityNotFoundFault fault = new EntityNotFoundFault(); fault.Message = "Error trying to get data on car."; fault.Description = "Couldn't find car with that id."; throw new FaultException <EntityNotFoundFault>(fault); } else { return(car); } }
public async Task DeleteAsync(Guid id) { using (var db = _dbFactory.Create(PersonalFilePermissions.EditOperation)) { var entity = await db.Set <MaterialStimulation>() .Where(x => x.ID == id && !x.RecordDeleted.HasValue) .SingleOrDefaultAsync() .ConfigureAwait(false); if (entity == null) { throw EntityNotFoundFault.Create(id, typeof(MaterialStimulation)); } entity.RecordDeleted = DateTime.Now; entity.RecordDeletedByUserID = _user.Id; await db.SaveChangesAsync().ConfigureAwait(false); } }
/// <summary> /// Get data on booking object with given bookingid. /// </summary> /// <param name="bookingId">Id of the booking to get data on.</param> /// <returns>Booking object with given id.</returns> public Booking GetBooking(int bookingId) { int i = 0; if (null == repos.FindBy <Booking>(booking => booking.Id == bookingId).FirstOrDefault() || int.TryParse(bookingId.ToString(), out i) == false) { EntityNotFoundFault fault = new EntityNotFoundFault { Message = "Error-no booking found.", Description = "Could not find booking with that id in database, please try again." }; throw new FaultException <EntityNotFoundFault>(fault); } else { return(repos.DataSet <Booking>() .Where(b => b.Id == bookingId) .Include(b => b.BookingCustomer) .Include(c => c.Car) .FirstOrDefault()); } }
public async Task <MaterialStimulationDto> SaveAsync(MaterialStimulationDto dto) { if (dto == null) { throw new ArgumentNullException(nameof(dto)); } using (var db = _dbFactory.Create(PersonalFilePermissions.EditOperation)) { var personalFile = db.Set <PersonalFile>().SingleOrDefault(x => x.ID == dto.PersonalFileId); MaterialStimulation entity; if (dto.ID == Guid.Empty) { entity = new MaterialStimulation { ID = Guid.NewGuid(), RecordCreatedByUserID = _user.Id, PersonalFileId = dto.PersonalFileId, OrganizationId = personalFile.OrganizationId, }; db.Set <MaterialStimulation>().Add(entity); } else { entity = await db.Set <MaterialStimulation>() .Include(x => x.OrderHead) .SingleOrDefaultAsync(x => x.ID == dto.ID && !x.RecordDeleted.HasValue); if (entity == null) { throw EntityNotFoundFault.Create(dto.ID, typeof(MaterialStimulation)); } entity.RecordLastModifiedByUserID = _user.Id; entity.RecordLastModified = DateTime.Now; } if (entity.OrderHead == null) { entity.OrderHead = new OrderHead(); entity.RecordCreatedByUserID = _user.Id; entity.OrderHead.OrderDate = dto.OrderDate; entity.OrderHead.OrderNumber = dto.OrderNumber; entity.OrderHead.OrganizationId = personalFile.OrganizationId; } else if (entity.OrderHead.OrderDate != dto.OrderDate || entity.OrderHead.OrderNumber != dto.OrderNumber) { entity.OrderHead.OrderDate = dto.OrderDate; entity.OrderHead.OrderNumber = dto.OrderNumber; entity.OrderHead.RecordLastModified = DateTime.Now; entity.OrderHead.RecordLastModifiedByUserID = _user.Id; } var binder = _binderFactory.Create <MaterialStimulation, MaterialStimulationDto>(db); entity = binder.BindFrom(entity, dto); await db.SaveChangesAsync(); dto.ID = entity.ID; return(dto); } }