示例#1
0
        public async Task <ActionResult <LinUserResource> > UpdateUser(int uid, LinUserUpdateByAdminResource linUserUpdateByAdminResource)
        {
            var user = await _adminRepository.GetUserAsync(uid);

            if (user == null)
            {
                throw new NotFoundException
                      {
                          ErrorCode = ResultCode.UserNotFoundErrorCode
                      };
            }

            if (linUserUpdateByAdminResource.Email != user.Email)
            {
                var users = await _adminRepository.GetAllUsersAsync();

                if (users.Any(u => u.Email == linUserUpdateByAdminResource.Email))
                {
                    throw new BadRequestException
                          {
                              ErrorCode = ResultCode.UserEmailExistedErrorCode
                          };
                }
            }

            MyMapper.Map(linUserUpdateByAdminResource, user);

            _adminRepository.Update(user);

            if (!await UnitOfWork.SaveAsync())
            {
                throw new Exception("Save Failed!");
            }

            var resource = MyMapper.Map <LinUserResource>(user);

            return(Ok(resource));
        }
示例#2
0
        public override UserDTO Update(int objectId, UserInsertRequest updateRequest)
        {
            if (updateRequest.Password != updateRequest.PasswordConfirmation)
            {
                return(null);
            }

            User user = _eTravelContext.Users.Find(objectId);

            if (user == null)
            {
                return(null);
            }
            _eTravelContext.Entry <User>(user).State = EntityState.Detached;

            var updateEntity = MyMapper.Map <User>(updateRequest);

            user = MyMapper.Map <User>(updateEntity);
            user.PasswordSalt = GenerateSalt();
            user.PasswordHash = GenerateHash(updateEntity.PasswordSalt, updateRequest.Password);
            user.Id           = objectId;
            _eTravelContext.Users.Update(user);
            _eTravelContext.SaveChanges();
            if (updateRequest.Roles.Count != 0)
            {
                var userRoles = _eTravelContext.UserRoles.Where(_ => _.UserId == updateEntity.Id).ToList();
                _eTravelContext.UserRoles.RemoveRange(userRoles);
                _eTravelContext.SaveChanges();
                foreach (var role in updateRequest.Roles)
                {
                    _eTravelContext.UserRoles.Add(new UserRoles {
                        UserId = updateEntity.Id, RoleId = role
                    });
                    _eTravelContext.SaveChanges();
                }
            }
            return(MyMapper.Map <UserDTO>(updateEntity));
        }
示例#3
0
        public async Task <ActionResult <LinGroupWithAuthsResource> > AddGroup(LinGroupAddResource linGroupAddResource)
        {
            var group = MyMapper.Map <LinGroupAddResource, LinGroup>(linGroupAddResource);

            var dispatchedMetas = PermissionMetaHandler.GetAllDispatchedMetas();

            var permissionMetas = dispatchedMetas.Where(meta => linGroupAddResource.Auths.Contains(meta.Auth));

            var linAuths = MyMapper.Map <IEnumerable <PermissionMeta>, IEnumerable <LinAuth> >(permissionMetas);

            group.LinAuths = linAuths.ToList();

            _adminRepository.Add(group);

            if (!await UnitOfWork.SaveAsync())
            {
                throw new Exception("Save Failed!");
            }

            var resource = MyMapper.Map <LinGroup, LinGroupWithAuthsResource>(group);

            return(CreatedAtRoute("GetGroup", new { id = resource.Id }, resource));
        }
        public override UserDTO Insert(UserInsertRequest InsertRequest)
        {
            if (InsertRequest.Password != InsertRequest.PasswordConfirmation)
            {
                return(null);
            }
            var newEntity = MyMapper.Map <User>(InsertRequest);

            newEntity.PasswordSalt = GenerateSalt();
            newEntity.PasswordHash = GenerateHash(newEntity.PasswordSalt, InsertRequest.Password);
            _context.Add(newEntity);
            _context.SaveChanges();

            foreach (var item in InsertRequest.Roles)
            {
                _context.UserRoles.Add(new UserRole {
                    RoleId = item.Id, UserId = newEntity.Id
                });
            }

            _context.SaveChanges();
            return(MyMapper.Map <UserDTO>(newEntity));
        }
        public virtual ActionResult <PaymentResponse> GetPayment(Guid body)
        {
            try
            {
                Log.LogDebug($"Finding payment {body}");

                var result = PaymentService.GetPayment(body);

                var response = MyMapper.Map <PaymentResponse>(result);

                if (response.Status == PaymentStatus.RequestSucceded)
                {
                    Log.LogDebug($"Payment response 200 {body}");
                    return(Ok(response));
                }
                else if (response.Status == PaymentStatus.RequestDoesNotExist)
                {
                    Log.LogDebug($"Payment response 404 {body}");
                    return(NotFound(response));
                }
                else if (response.Status == PaymentStatus.Error)
                {
                    Log.LogDebug($"Payment response 500 {body}");
                    return(StatusCode(500, response));
                }
                else
                {
                    Log.LogDebug($"Payment response 400 {body}");
                    return(BadRequest(response));
                }
            }
            catch (Exception ex)
            {
                Log.LogError(ex, ex.Message);
                return(BadRequest(ex));
            }
        }
        public void TestAnnotationCacheSetting2()
        {
            var mapper = new MyMapper();

            var userAgentAnnotationAnalyzer = new UserAgentAnnotationAnalyzer <TestRecord>();

            // To make sure the internals behave as expected
            var userAgentAnalyzerField = userAgentAnnotationAnalyzer.GetType().GetField("userAgentAnalyzer", BindingFlags.NonPublic | BindingFlags.Instance);

            userAgentAnalyzerField.GetValue(userAgentAnnotationAnalyzer).Should().BeNull();

            // Initial value
            userAgentAnnotationAnalyzer.CacheSize.Should().Be(UserAgentAnalyzer.DEFAULT_PARSE_CACHE_SIZE);

            userAgentAnnotationAnalyzer.Initialize(new MyMapper());

            var userAgentAnalyzer = (UserAgentAnalyzer)userAgentAnalyzerField.GetValue(userAgentAnnotationAnalyzer);

            userAgentAnalyzer.Should().NotBeNull();
            // Initial value
            userAgentAnnotationAnalyzer.CacheSize.Should().Be(UserAgentAnalyzer.DEFAULT_PARSE_CACHE_SIZE);
            userAgentAnalyzer.CacheSize.Should().Be(UserAgentAnalyzer.DEFAULT_PARSE_CACHE_SIZE);

            // Setting and getting while there IS a UserAgentAnalyzer
            userAgentAnnotationAnalyzer.SetCacheSize(1234);
            userAgentAnnotationAnalyzer.CacheSize.Should().Be(1234);
            userAgentAnalyzer.CacheSize.Should().Be(1234);

            userAgentAnnotationAnalyzer.DisableCaching();
            userAgentAnnotationAnalyzer.CacheSize.Should().Be(0);
            userAgentAnalyzer.CacheSize.Should().Be(0);

            userAgentAnnotationAnalyzer.SetCacheSize(4567);
            userAgentAnnotationAnalyzer.CacheSize.Should().Be(4567);
            userAgentAnalyzer.CacheSize.Should().Be(4567);
        }
示例#7
0
        public override IEnumerable <ReservationDTO> Get(ReservationSearchRequest request)
        {
            var query = _eTravelContext.Set <Reservation>().AsQueryable();

            query = MyMapper.Map <List <Reservation> >(base.Get(request)).AsQueryable();


            if (request.FromPersons != 0 || request.ToPersons != 0)
            {
                query = query.Where(_ => request.FromPersons <= _.NumberOfPersons && request.ToPersons >= _.NumberOfPersons);
            }

            if (request.FromDate.ToString() != "01-Jan-01 1:00:00 AM" && request.ToDate.ToString() != "01-Jan-01 1:00:00 AM")
            {
                query = query.Where(_ => request.FromDate <= _.DateReserved && request.ToDate >= _.DateReserved);
            }
            if (request.FromPrice != 0 || request.ToPrice != 0)
            {
                query = query.Where(_ => request.FromPrice <= _.TotalPrice && request.ToPrice >= _.TotalPrice);
            }
            if (request.FromDays != 0 || request.ToDays != 0)
            {
                query = query.Where(_ => request.FromDays <= _.NumberOfDays && request.ToDays >= _.NumberOfDays);
            }


            //query = query.Where(_ => _.Canceled == request.Canceled
            //                    || _.DateReserved == request.DateReserved
            //                    || _.NumberOfPersons == request.NumberOfPersons);
            //                    || (request.FromPrice <= _.TotalPrice && request.ToPrice >= _.TotalPrice)
            //                    || (request.FromDate <= _.DateReserved && request.ToDate >= _.DateReserved)
            //                    || (request.FromPersons <= _.NumberOfPersons && request.ToPersons >= _.NumberOfPersons));
            var result = MyMapper.Map <List <ReservationDTO> >(query.ToList());

            return(result);
        }
示例#8
0
 public ActionResult SaveUpdatedResult(Models.Product pr)
 {
     if (ModelState.IsValid)
     {
         try {
             QuickKartRepository rep = new QuickKartRepository();
             MyMapper <Models.Product, Product> mapObj = new MyMapper <Models.Product, Product>();
             bool status = rep.UpdateProduct(mapObj.Translate(pr));
             if (status)
             {
                 return(RedirectToAction("ViewProducts"));
             }
             else
             {
                 return(View("Error"));
             }
         }
         catch (Exception ex)
         {
             return(View("Error"));
         }
     }
     return(View("UpdateResults", pr));
 }
        /// <summary>
        /// MyMapper - Map extension method
        /// </summary>
        /// <typeparam name="TSourceList">The source list type</typeparam>
        /// <typeparam name="TDestinationList">The destination list type</typeparam>
        /// <param name="source">The source list</param>
        /// <param name="map">MyMapper rules for the mapping</param>
        /// <param name="automap">Flag to indicate if to use automapping</param>
        /// <returns>The destination list <see cref="IEnumerable{TDestinationList}"/></returns>
        public static IEnumerable <TDestinationList> Map <TSourceList, TDestinationList>(
            this IEnumerable <TSourceList> source,
            Func <IMyMapperRules <TSourceList, TDestinationList>, TDestinationList> map = null,
            bool automap = true
            )
            where TSourceList : class
            where TDestinationList : class, new()
        {
            if (source == null)
            {
                return(null);
            }

            IMyMapper <TSourceList, TDestinationList> mapper;

            return(source.Select(src =>
            {
                if (src == null)
                {
                    return null;
                }

                mapper = new MyMapper <TSourceList, TDestinationList>();

                mapper.Map(src, automap);

                if (map != null)
                {
                    return map(mapper);
                }
                else
                {
                    return mapper.Exec();
                }
            }));
        }
示例#10
0
 public List <Product> GetAll()
 {
     return(MyMapper.MapToSameTypeList(_productDal.GetList()));
 }
示例#11
0
 public Product Update(Product product)
 {
     return(_productDal.Update(MyMapper.MapToSameType(product)));
 }
示例#12
0
 public NextRepairDTO GetNextRepair(int?id)
 {
     return(MyMapper <NextRepair, NextRepairDTO> .Map(DB.NextRepairs.GetById(id.Value)));
 }
示例#13
0
 public IEnumerable <EquipmentDTO> GetAllEquipments()
 {
     return(MyMapper <Equipment, EquipmentDTO> .Map(DB.Equipments.GetAll()));
 }
 public void Setup()
 {
     MyMapper.Initialize();
     state = GetState();
 }
示例#15
0
 public void Initialize()
 {
     myMapper = new MyMapper();
 }
示例#16
0
 public ProductService(ShopDbContext ctx, MyMapper mapper)
 {
     this.ctx    = ctx;
     this.mapper = mapper.CreateMappings();
 }
        public ActionResult <LinUserWithAuthsResource> GetAllowedAuths()
        {
            var resource = MyMapper.Map <LinUserWithAuthsResource>(CurrentUser);

            return(Ok(resource));
        }
        public ActionResult <LinUserResource> Information()
        {
            var resource = MyMapper.Map <LinUserResource>(CurrentUser);

            return(Ok(resource));
        }
示例#19
0
 public void TestInitialize()
 {
     _mockMapper = Substitute.For <IMapper>();
     _myMapper   = new MyMapper(_mockMapper);
 }
示例#20
0
 public void SetUp()
 {
     _myMapper = new MyMapper();
 }
示例#21
0
        static void Main(string[] args)
        {
            IMyMapper mapper = new MyMapper();

            var obj = new FirstObject()
            {
                Bool       = true,
                Decimal    = 0.5,
                Float      = 0.7f,
                Double     = 4.3,
                Int        = 4,
                String     = "String",
                NestedType = new NestedType()
                {
                    String = "String",
                    Int    = 5
                },
                Struct2 = new Struct()
                {
                    String = "String",
                    Int    = 5
                },
                StringIntoInt     = "5",
                DoubleIntoDecimal = 5.2,
                DecimalIntoInt    = new decimal(2.4),
                IntIntoString     = 13,
                IntArray          = new[] { 4, 3, 6, 2 },
                EnumerableDoubles = new List <double>()
                {
                    4.4,
                    5.3
                },
                Dictionary = new Dictionary <string, int>()
                {
                    { "String1", 1 },
                    { "String2", 2 },
                    { "String3", 3 },
                    { "String4", 4 },
                },
                ArrayIntoList = new[]
                {
                    "String1",
                    "String2",
                    "String3",
                    "String4",
                    "String5",
                },
                ListIntoArray = new List <int>
                {
                    2, 4, 5, 1
                },
                ListNestedTypes = new List <NestedType>()
                {
                    new NestedType()
                    {
                        String = "5",
                        Int    = 3
                    },
                    new NestedType()
                    {
                        String = "3",
                        Int    = 5
                    }
                }
            };

            var secondObject = mapper.Map <SecondObject>(obj);
        }
示例#22
0
 public IEnumerable <LastRepairDTO> GetAllLastRepairs()
 {
     return(MyMapper <LastRepair, LastRepairDTO> .Map(DB.LastRepairs.GetAll()));
 }
示例#23
0
 public LastRepairDTO GetLastRepair(int?id)
 {
     return(MyMapper <LastRepair, LastRepairDTO> .Map(DB.LastRepairs.GetById(id.Value)));
 }
示例#24
0
 public User GetByUserNameAndPassword(string userName, string password)
 {
     return(MyMapper.MapToSameType(_userDal.Get(p => p.UserName == userName && p.Password == password)));
 }
 public ChitGroupListDataService(DatabaseContext context)
 {
     MyMapper.Initialize();
     this._context = context;
 }
示例#26
0
 public List <Entities.ComplexTypes.UserRole> GetUserRoles(User user)
 {
     return(MyMapper.MapToSameType(_userDal.GetUserRoles(user)));
 }
示例#27
0
 public BrigadeDTO GetBrigade(int?id)
 {
     return(MyMapper <Brigade, BrigadeDTO> .Map(DB.Brigades.GetById(id.Value)));
 }
示例#28
0
 public IEnumerable <DepartmentDTO> GetAllDepartments()
 {
     return(MyMapper <Department, DepartmentDTO> .Map(DB.Departments.GetAll()));
 }
示例#29
0
 public EquipmentDTO GetEquipment(int?id)
 {
     return(MyMapper <Equipment, EquipmentDTO> .Map(DB.Equipments.GetById(id.Value)));
 }
示例#30
0
 public IEnumerable <NextRepairDTO> GetAllNextRepairs()
 {
     return(MyMapper <NextRepair, NextRepairDTO> .Map(DB.NextRepairs.GetAll()));
 }