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)); }
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)); }
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); }
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); }
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(); } })); }
public List <Product> GetAll() { return(MyMapper.MapToSameTypeList(_productDal.GetList())); }
public Product Update(Product product) { return(_productDal.Update(MyMapper.MapToSameType(product))); }
public NextRepairDTO GetNextRepair(int?id) { return(MyMapper <NextRepair, NextRepairDTO> .Map(DB.NextRepairs.GetById(id.Value))); }
public IEnumerable <EquipmentDTO> GetAllEquipments() { return(MyMapper <Equipment, EquipmentDTO> .Map(DB.Equipments.GetAll())); }
public void Setup() { MyMapper.Initialize(); state = GetState(); }
public void Initialize() { myMapper = new MyMapper(); }
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)); }
public void TestInitialize() { _mockMapper = Substitute.For <IMapper>(); _myMapper = new MyMapper(_mockMapper); }
public void SetUp() { _myMapper = new MyMapper(); }
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); }
public IEnumerable <LastRepairDTO> GetAllLastRepairs() { return(MyMapper <LastRepair, LastRepairDTO> .Map(DB.LastRepairs.GetAll())); }
public LastRepairDTO GetLastRepair(int?id) { return(MyMapper <LastRepair, LastRepairDTO> .Map(DB.LastRepairs.GetById(id.Value))); }
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; }
public List <Entities.ComplexTypes.UserRole> GetUserRoles(User user) { return(MyMapper.MapToSameType(_userDal.GetUserRoles(user))); }
public BrigadeDTO GetBrigade(int?id) { return(MyMapper <Brigade, BrigadeDTO> .Map(DB.Brigades.GetById(id.Value))); }
public IEnumerable <DepartmentDTO> GetAllDepartments() { return(MyMapper <Department, DepartmentDTO> .Map(DB.Departments.GetAll())); }
public EquipmentDTO GetEquipment(int?id) { return(MyMapper <Equipment, EquipmentDTO> .Map(DB.Equipments.GetById(id.Value))); }
public IEnumerable <NextRepairDTO> GetAllNextRepairs() { return(MyMapper <NextRepair, NextRepairDTO> .Map(DB.NextRepairs.GetAll())); }