コード例 #1
0
        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);
        }
コード例 #2
0
        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);
        }
コード例 #3
0
        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);
        }
コード例 #4
0
        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);
        }
コード例 #5
0
        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);
        }
コード例 #6
0
        /// <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);
            }
        }
コード例 #7
0
        /// <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);
            }
        }
コード例 #8
0
        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);
            }
        }
コード例 #9
0
        /// <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());
            }
        }
コード例 #10
0
        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);
            }
        }