Beispiel #1
0
        public void Register(object obj)
        {
            var group    = ConvertDTO(obj);
            var hasGroup = _repository.Get(group.Name);

            if (hasGroup != null)
            {
                throw new Exception(Errors.DuplicateEmail);
            }

            _repository.Add(group);
        }
Beispiel #2
0
        public void InitSeedData()
        {
            var isDataExists = _groupRepository.GetAll().Result;

            if (isDataExists.Count() > 0)
            {
                return;
            }

            var silverGroup   = new Group("Silver", 10);
            var platinumGroup = new Group("Platinum", 30);
            var goldGroup     = new Group("Gold", 20);

            var customerOne   = new Customer("Mr. Saiful", silverGroup);
            var customerTwo   = new Customer("Mr. Riaz", platinumGroup);
            var customerThree = new Customer("Mrs. Anika", goldGroup);
            var customerFour  = new Customer("Mr. Selim", silverGroup);
            var customerFive  = new Customer("Mr. Talha", goldGroup);

            var babyToy    = new Product("Baby Toy", 350);
            var babySoap   = new Product("Baby Soap", 80);
            var babyFood   = new Product("Baby Food", 150);
            var babyHygine = new Product("Baby Hygine", 50);
            var babyPampas = new Product("Baby Pampas", 120);
            var babyDoll   = new Product("Baby Doll", 560);
            var babyLotion = new Product("Baby Lotion", 260);
            var book       = new Product("Book", 230);
            var pen        = new Product("Pen", 50);
            var paper      = new Product("Paper", 140);

            _groupRepository.Add(silverGroup);
            _groupRepository.Add(goldGroup);
            _groupRepository.Add(platinumGroup);

            _customerRepository.Add(customerOne);
            _customerRepository.Add(customerTwo);
            _customerRepository.Add(customerThree);
            _customerRepository.Add(customerFour);
            _customerRepository.Add(customerFive);

            _productRepository.Add(babyToy);
            _productRepository.Add(babySoap);
            _productRepository.Add(babyFood);
            _productRepository.Add(babyHygine);
            _productRepository.Add(babyPampas);
            _productRepository.Add(babyDoll);
            _productRepository.Add(babyLotion);
            _productRepository.Add(book);
            _productRepository.Add(pen);
            _productRepository.Add(paper);

            _unitOfWork.Commit().Wait();
        }
Beispiel #3
0
        public InsertDataGroupResponse InsertDataGroup(InsertDataGroupRequest request)
        {
            var valid = new ValidationHelper().Initialize(request.Group);

            InsertDataGroupResponse response = new InsertDataGroupResponse();

            try
            {
                if (!valid.IsValid)
                {
                    foreach (var error in valid.Errors)
                    {
                        response.Messages.Add(error.Message);
                    }
                }
                else
                {
                    using (TransactionScope transScope = new TransactionScope(TransactionScopeOption.Required, new TransactionOptions {
                        IsolationLevel = IsolationLevel.ReadCommitted
                    }))
                    {
                        SecurityHelper.InitializeAntiXSS(request.Group);
                        _groupRepo.Add(request.Group);
                        transScope.Complete();
                    }
                }
            }
            catch (Exception ex)
            {
                response.Messages.Add(ex.ToString());
                LogFileException.LogError(ex, dtStart);
            }
            return(response);
        }
        public TGroup Create(string tenant, string name)
        {
            if (String.IsNullOrWhiteSpace(tenant))
            {
                throw new ValidationException(Resources.ValidationMessages.TenantRequired);
            }
            if (String.IsNullOrWhiteSpace(name))
            {
                throw new ValidationException(Resources.ValidationMessages.NameRequired);
            }

            if (NameAlreadyExists(tenant, name))
            {
                throw new ValidationException(Resources.ValidationMessages.NameAlreadyInUse);
            }

            var grp = this.groupRepository.Create();

            grp.ID      = Guid.NewGuid();
            grp.Tenant  = tenant;
            grp.Name    = name;
            grp.Created = grp.LastUpdated = UtcNow;

            groupRepository.Add(grp);

            return(grp);
        }
Beispiel #5
0
        public void Add(IBusiness business, ILocation location, IUserBusiness userBusiness, IGroup group)
        {
            try
            {
                Lock();

                _businessRepository.Add(business);
                _locationRepository.Add(location);
                _groupRepository.Add(group);

                foreach (var email in business.Members)
                {
                    var userGroup = new UserGroup
                    {
                        Id   = group.Id,
                        Name = group.Name,
                        Role = GroupRoles.Admin
                    };

                    _userRepository.AddBusinessWithEmail(userBusiness, email);
                    _userRepository.AddGroupWithEmail(userGroup, email);
                }
            }
            catch (Exception)
            {
                //TODO: Rollback logic
                throw new Exception("Failed to perform atomic action - " + Desc);
            }
            finally
            {
                Unlock();
            }
        }
        public async Task <IActionResult> CreateGroup(string userId, string groupName)
        {
            User user = await userManager.FindByIdAsync(userId);

            if (user != null)
            {
                Group group = new Group
                {
                    GroupId    = Guid.NewGuid().ToString(),
                    Events     = new List <Event>(),
                    FreeTimes  = new List <FreeTime>(),
                    GroupUsers = new List <GroupUser>(),
                    Name       = groupName,
                    InvId      = Guid.NewGuid().ToString()
                };
                GroupUser groupUser = new GroupUser
                {
                    User    = user,
                    UserId  = user.Id,
                    GroupId = group.GroupId,
                    Group   = group
                };
                group.GroupUsers.Add(groupUser);


                groupRepository.Add(group);
                // groupUserRepository.Add(groupUser);
                //GroupEntity groupEntity = new GroupEntity(group);
                //var result = JsonConvert.SerializeObject(groupEntity);
                return(Ok());
            }

            return(BadRequest("User not found."));
        }
Beispiel #7
0
        public async Task <IActionResult> CreateMessage(int userId, MessageForCreationDto messageForCreationDto)
        {
            var sender = await _repo.GetUser(userId);

            if (sender.Id != int.Parse(User.FindFirst(ClaimTypes.NameIdentifier).Value))
            {
                return(Unauthorized());
            }
            messageForCreationDto.SenderId = userId;
            var recipient = await _repo.GetUser(messageForCreationDto.RecipientId);

            if (recipient == null)
            {
                return(BadRequest("لم يتم الوصول للمرسل إليه"));
            }
            var message = _mapper.Map <Message>(messageForCreationDto);

            _repo.Add(message);
            if (await _repo.SaveAll())
            {
                var messageToReturn = _mapper.Map <MessageToReturnDto>(message);
                // حل مشكلة No Route باضافة ال userId,
                return(CreatedAtRoute(nameof(GetMessage), new { userId, id = message.Id }, messageToReturn));
            }
            throw new Exception("حدثت مشكلة أثناء حفظ الرسالة الجديدة");
        }
Beispiel #8
0
        public async Task <IActionResult> AddGroup(GroupDto newGroup)
        {
            var mappedGroup = _mapper.Map <Group>(newGroup);
            var addedGroup  = await _groupRepo.Add(mappedGroup);

            return(CreatedAtRoute("GetGroup", new { groupId = addedGroup.Id }, _mapper.Map <GroupDto>(addedGroup)));
        }
Beispiel #9
0
        public void Add(Group group)
        {
            ValidateGroup(group);
            ValidateDuplicatedGroup(group);

            _groupRepository.Add(group);
        }
Beispiel #10
0
        public async Task <bool> Execute(CreateGroupStationInputModel groupStationInput)
        {
            var group = new GroupStation(groupStationInput.Name, groupStationInput.CapacityAmps);

            Parallel.ForEach(groupStationInput.ChargeStations, chargeStation =>
            {
                var newChargStation = new ChargeStation(chargeStation.Name);

                var newConnectorList = CreateConnectors(chargeStation, newChargStation);

                newChargStation.Connectors.AddRange(newConnectorList);

                group.AddChargeStation(newChargStation);
            });

            if (group.IsCapacityOfGroup() > group.CapacityAmps)
            {
                var numberOfExcessConnector = group.IsCapacityOfGroup() - group.CapacityAmps;

                HandlerMessage = $"The capactiy of Connector was excessed. You may remove {numberOfExcessConnector} of Connectors";

                return(false);
            }

            await _groupRepository.Add(group);

            HandlerMessage = "Group has been added";

            return(true);
        }
        public async Task <bool> Handle(GroupInsertCommand command, CancellationToken cancellationToken)
        {
            var group = Group.Create(command.Description);

            _groupRepository.Add(group);

            return(await _groupRepository.UnitOfWork.SaveEntitiesAsync(cancellationToken));
        }
        public Group ProvisionGroup(ProvisionGroupCommand command)
        {
            var tenant = GetExistingTenant(command.TenantId);
            var group  = tenant.ProvisionGroup(command.GroupName, command.Description);

            _groupRepository.Add(group);
            return(group);
        }
Beispiel #13
0
        public IActionResult CreateGroup(string name, List <RuleParameterMiddleMan> parameters)
        {
            RuleGroup group = new RuleGroup(name, parameters.Select(param => param.OutgoingRuleParameter).ToList()); // performs the type lookups

            _groupRepository.Add(group);

            return(CurrentGroups());
        }
Beispiel #14
0
 /// <summary>
 /// Checks the unique key in group name
 /// </summary>
 /// <param name="group"></param>
 /// <returns></returns>
 public bool Add(Group group)
 {
     if (_groupRepository.GroupNameExists(group.Name))
     {
         return(false);
     }
     _groupRepository.Add(group);
     return(true);
 }
Beispiel #15
0
 public IActionResult PostGroup([FromBody] Group group)
 {
     using (var scope = new TransactionScope())
     {
         _groupRepository.Add(group);
         scope.Complete();
         return(CreatedAtAction(nameof(GetGroup), new { id = group.GroupId }, group));
     }
 }
 public IActionResult Create(Group group)
 {
     if (!ModelState.IsValid)
     {
         return(View(group));
     }
     _repository.Add(group);
     _repository.Save();
     return(RedirectToAction("SectionDetails", "Service", new { id = group.SectionId }));
 }
        public ActionResult <Group> PostGroup(GroupDTO group)
        {
            Group groupToCreate = new Group {
                GroupName = group.GroupName, MaxPrice = (int)group.MaxPrice, PartyDate = group.PartyDate, Public = group.Public
            };

            _groupRepository.Add(groupToCreate);
            _groupRepository.SaveChanges();
            return(Ok());
        }
        public void SeedData()
        {
            var isDataExists = _groupRepository.GetAll().Result;

            if (isDataExists.Count() > 0)
            {
                Assert.Pass();
                return;
            }
            var silverGroup   = new Group("Silver", 10);
            var platinumGroup = new Group("Platinum", 50);
            var goldGroup     = new Group("Gold", 30);

            var customerOne   = new Customer("Saiful", silverGroup);
            var customerTwo   = new Customer("Riaz", platinumGroup);
            var customerThree = new Customer("Faisal", goldGroup);

            var babyToy    = new Product("Baby Toy", 100);
            var babySoap   = new Product("Baby Soap", 80);
            var babyFood   = new Product("Baby Food", 150);
            var babyHygine = new Product("Baby Hygine", 50);
            var babyPampas = new Product("Baby Pampas", 120);

            _groupRepository.Add(silverGroup);
            _groupRepository.Add(goldGroup);
            _groupRepository.Add(platinumGroup);

            _customerRepository.Add(customerOne);
            _customerRepository.Add(customerTwo);
            _customerRepository.Add(customerThree);

            _productRepository.Add(babyToy);
            _productRepository.Add(babySoap);
            _productRepository.Add(babyFood);
            _productRepository.Add(babyHygine);
            _productRepository.Add(babyPampas);

            bool result = _unitOfWork.Commit().Result;


            Assert.IsTrue(result);
        }
Beispiel #19
0
        public IActionResult Create(Group group)
        {
            if (ModelState.IsValid)
            {
                group.GroupName = group.GroupName.ToUpper();

                _groupRepository.Add(group);
                return(RedirectToAction("Index"));
            }
            return(View());
        }
Beispiel #20
0
        public void Add(GroupDto group_in)
        {
            var group = new Group(group_in.ID, group_in.Name);

            foreach (SupplierDto supplierDto in group_in.Suppliers)
            {
                group.Suppliers.Add(SupplierRepository.GetById(supplierDto.ID));
            }

            GroupRepository.Add(group);
        }
Beispiel #21
0
        public async Task <IActionResult> InsertUserCountry(UserCountryToCreateDto userCountryToCreateDto)
        {
            var userCountryToCreate = _mapper.Map <UserCountry> (userCountryToCreateDto);

            _repo.Add(userCountryToCreate);
            if (await _repo.SaveAll())
            {
                return(Ok(userCountryToCreate));
            }
            return(BadRequest("فشل في الاضافة"));
        }
Beispiel #22
0
        public async Task <ActionResult> Create([FromBody] GroupDto item)
        {
            var group = Domain.Entities.Group.Create(item);
            await _groupRepository.Add(group);

            return(CreatedAtAction(
                       nameof(GetById),
                       new { id = group.Id },
                       new { id = group.Id }
                       ));
        }
        public async Task <IActionResult> InsertUserVillage(UserVillageToCreateDto userVillageToCreateDto)
        {
            var village = _mapper.Map <UserVillage>(userVillageToCreateDto);

            _repo.Add(village);
            if (await _repo.SaveAll())
            {
                return(Ok(village));
            }
            return(BadRequest("فشل في الاضافة"));
        }
Beispiel #24
0
        public async Task <IActionResult> CreateGroup([FromBody] SaveGroupResource saveGroupResource)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            repository.Add(saveGroupResource);
            await unitOfWork.CompleteAsync();

            return(Ok(saveGroupResource));
        }
Beispiel #25
0
        //public IEnumerable<User> GetUsersByStatus(string status)
        //{
        //    using (var ctx = new DBBase()) { }
        //    return repository.GetAll().Where(
        //        p => string.Equals(p.Status, status, StringComparison.OrdinalIgnoreCase));
        //}

        public HttpResponseMessage PostGroup(Group item)
        {
            using (var ctx = new DBBase()) { }
            item = repository.Add(item);
            var response = Request.CreateResponse <Group>(HttpStatusCode.Created, item);

            string uri = Url.Link("DefaultApi", new { id = item.Id });

            response.Headers.Location = new Uri(uri);
            return(response);
        }
Beispiel #26
0
        public void CreateGroup(Group group)
        {
            var checkIfExists = this._groupRepository.GetGroupByName(group.Name);

            if (checkIfExists != null)
            {
                throw new ArgumentException("Group name should be unique");
            }
            _groupRepository.Add(group);
            this._unitOfWork.Commit();
        }
            public async Task <IResult> Handle(CreateGroupCommand request, CancellationToken cancellationToken)
            {
                var group = new Group
                {
                    GroupName = request.GroupName
                };

                _groupDal.Add(group);
                await _groupDal.SaveChangesAsync();

                return(new SuccessResult(Messages.GroupAdded));
            }
Beispiel #28
0
        public void CreateGroup(GroupViewModel newGroup, int userId)
        {
            int groupId = _groupRepository.Add(newGroup.ToEntity());
            var role    = _roleRepository.Get(r => r.Name.Equals(RoleNames.ROLE_OWNER)).Single();

            GroupMember groupMember = new GroupMember()
            {
                GroupId = groupId, UserId = userId, RoleId = role.Id, JoinedAt = DateTime.Now
            };

            _groupMemberRepository.AddUserToGroup(groupMember);
        }
        public async Task <IActionResult> AddUserClass(int userClassId, UserClassForCreateDto userClassForCreateDto)
        {
            var userClass = _mapper.Map <UserClass> (userClassForCreateDto);

            _repo.Add(userClass);

            if (await _repo.SaveAll())
            {
                return(Ok(userClass));
            }
            return(BadRequest("فشل في الاضافة"));
        }
Beispiel #30
0
        public async Task <IActionResult> InsertCity(CityForInsertDto cityForInsertDto)
        {
            var city = _mapper.Map <UserCity>(cityForInsertDto);

            _repo.Add(city);

            if (await _repo.SaveAll())
            {
                return(Ok(city));
            }
            return(BadRequest("فشل في الاضافة"));
        }