Пример #1
0
        /// <summary>
        /// Changes the active status of an associate
        /// This is essentially the 'Delete' method
        /// </summary>
        public async Task <bool> DeactivateAssociate(AssociateDto delAssociate)
        {
            if (associateLogic.ValidateRestData(delAssociate))
            {
                //the following two lines gather all batches and all genders from the database
                var serviceGenders = await client.GetGenderAsync();

                var serviceBatches = await client.GetBatchesAsync();

                // the following two lines convert the batch/gender Name to the matching ID as a string
                delAssociate.Gender = serviceGenders.FirstOrDefault(g => g.Name.Equals(delAssociate.Gender)).GenderID.ToString();
                delAssociate.Batch  = serviceBatches.FirstOrDefault(b => b.Name.Equals(delAssociate.Batch)).BatchID.ToString();

                // The following two lines add an API call to the Housing side to trigger a secondary delete
                var thestring = HttpContext.Current.Request.Url.Scheme + "://" + HttpContext.Current.Request.Url.Host + "/workforce-housing-rest/api/housingdata";
                var theUri    = new Uri(thestring);
                // Deletes the associated Housing data attached to the associate being deleted
                await HRConnector.GetDeleteResponse(theUri, delAssociate.AssociateID.ToString());

                // Pass converted data down to Data layer and await a pass/fail response
                return(await client.DeleteAssociateAsync(associateLogic.MapToSoap(delAssociate)));
            }
            else
            {
                return(false);
            }
        }
Пример #2
0
        /// <summary>
        /// This is the basic 'Update' method for Associate
        /// </summary>
        public async Task <bool> UpdateAssociate(AssociateDto update)
        {
            if (associateLogic.ValidateRestData(update))
            {
                // collect all genders and batches
                var serviceGenders = await client.GetGenderAsync();

                var serviceBatches = await client.GetBatchesAsync();

                // convert Gender Name and Batch Name to the associated ID
                update.Gender = serviceGenders.FirstOrDefault(g => g.Name.Equals(update.Gender)).GenderID.ToString();
                update.Batch  = serviceBatches.FirstOrDefault(b => b.Name.Equals(update.Batch)).BatchID.ToString();

                // store newly updated object and map it
                var keepStatus = associateLogic.MapToSoap(update);

                // maintain 'Active' status so that it doesn't auto convert to false
                keepStatus.Active = true;

                // Pass converted data down to Data layer and await a pass/fail response
                return(await client.UpdateAssociateAsync(keepStatus));
            }
            else
            {
                return(false);
            }
        }
Пример #3
0
        public bool Create(AssociateDto associateDto)
        {
            try
            {
                _context.Associates.Add(new Associate()
                {
                    Agreement = new Agreement()
                    {
                        Description        = associateDto.Agreement.Description,
                        DiscountAmount     = associateDto.Agreement.DiscountAmount,
                        DiscountPercentual = associateDto.Agreement.DiscountPercentual
                    },
                    Customer = new Customer()
                    {
                        Description = associateDto.Customer.Description,
                        Document    = associateDto.Customer.Document,
                        Type        = associateDto.Customer.Type
                    },
                    Quantity = associateDto.Quantity
                });

                _context.SaveChanges();

                return(true);
            }
            catch
            {
                return(false);
            }
        }
        /// <summary>
        /// Validates the data stored in the Dto being passed through from the Client side
        /// </summary>
        public bool ValidateRestData(AssociateDto associate)
        {
            var context = new ValidationContext(associate);
            var results = new List <ValidationResult>();

            return(Validator.TryValidateObject(associate, context, results));
        }
        /// <summary>
        /// this method removes an assocaite from a room and decrease the current capacity
        /// </summary>
        /// <param name="associate"></param>
        /// <returns></returns>
        public async Task <bool> RemoveAssocFromRoom(InsertAssociateDto associate)
        {
            //FIND THE ASSOCIATE FROM A LIST OF ASSOCIATES
            AssociateDto assoc = (await consumerHelper.ConsumeAssociatesFromAPI()).Find(id => id.AssociateID.Equals(associate.AssociateId));
            //FIND THE APARTMENT
            ApartmentDto aptDto = (await logicHelper.ApartmentsGetAll()).Find(id => id.RoomID.Equals(associate.RoomId));

            //FIND THE HousingData
            HousingDataDto data = (await logicHelper.HousingDataGetAll()).Find(id => id.AssociateID.Equals(associate.AssociateId));

            //update the status to 3  WHERE THREE MEANS TO DELETE
            data.StatusID = 3;
            if (aptDto.CurrentCapacity > 0)
            {
                aptDto.CurrentCapacity--;
            }
            else
            {
                return(false);
            }

            bool passed = await logicHelper.UpdateApartment(aptDto);

            bool passed3 = await logicHelper.UpdateHousingData(data);

            return(passed && passed3);
        }
Пример #6
0
 public static Associate DtoToEntity(this AssociateDto associateDto)
 {
     return(new Associate()
     {
         Agreement = associateDto.Agreement.DtoToEntity(),
         Customer = associateDto.Customer.DtoToEntity(),
         Quantity = associateDto.Quantity
     });
 }
Пример #7
0
 public IActionResult Create([FromBody] AssociateDto associateDto)
 {
     if (_associateAppService.Create(associateDto))
     {
         return(Ok(associateDto));
     }
     else
     {
         return(BadRequest());
     }
 }
        /// <summary>
        /// this method inserts an assocaite into a room and increase the current capacity
        /// </summary>
        /// <param name="associate"></param>
        /// <returns></returns>
        public async Task <bool> InsertAssociateToRoom(InsertAssociateDto associate)
        {
            //FIND THE ASSOCIATE FROM A LIST OF ASSOCIATES
            AssociateDto assoc = (await consumerHelper.ConsumeAssociatesFromAPI()).Find(id => id.AssociateID.Equals(associate.AssociateId));
            //FIND THE APARTMENT
            ApartmentDto aptDto = (await logicHelper.ApartmentsGetAll()).Find(id => id.RoomID.Equals(associate.RoomId));

            List <HousingDataDto> tt = await logicHelper.HousingDataGetAll();

            HousingDataDto data = new HousingDataDto()
            {
                AssociateID = assoc.AssociateID,
                MoveInDate  = associate.MoveInDate,
                MoveOutDate = associate.MoveOutDate,
                RoomID      = associate.RoomId,
                StatusID    = 1
            };

            string RoomsGender = "Male";

            if (aptDto.GenderID == 2) //Female on gender table
            {
                RoomsGender = "Female";
            }

            if ((aptDto.CurrentCapacity < aptDto.MaxCapacity) && (RoomsGender == assoc.Gender))
            {
                aptDto.CurrentCapacity++;
            }
            else
            {
                return(false);
            }
            bool passed  = false;
            bool passed2 = false;

            if (tt.Exists(id => id.AssociateID.Equals(data.AssociateID)))
            {
                passed2 = await logicHelper.UpdateHousingData(data);
            }
            else
            {
                passed2 = await logicHelper.AddHousingData(data);
            }

            if (passed2)
            {
                passed = await logicHelper.UpdateApartment(aptDto);
            }


            return(passed && passed2);
        }
 public async Task <HttpResponseMessage> Delete([FromBody] AssociateDto associate)
 {
     try
     {
         var response = Request.CreateResponse(HttpStatusCode.OK, await logic.DeactivateAssociate(associate));
         logger.Info("Delete Associate Successful");
         return(response);
     }
     catch (Exception ex)
     {
         LogHelper.ErrorLogger(logger, ex);
         return(Request.CreateResponse(HttpStatusCode.BadRequest));
     }
 }
Пример #10
0
        /// <summary>
        /// Attempts to add a new associate after ensuring that the data entered is valid
        /// </summary>
        public async Task <bool> AddNewAssociate(AssociateDto newAssociate)
        {
            if (associateLogic.ValidateRestData(newAssociate))
            {
                // Collect all Genders and Batches
                var serviceGenders = await client.GetGenderAsync();

                var serviceBatch = await client.GetBatchesAsync();

                // Convert Name to ID
                newAssociate.Gender = serviceGenders.FirstOrDefault(g => g.Name.Equals(newAssociate.Gender)).GenderID.ToString();
                newAssociate.Batch  = serviceBatch.FirstOrDefault(b => b.Name.Equals(newAssociate.Batch)).BatchID.ToString();

                // Pass converted data down to Data layer and await a pass/fail response
                return(await client.InsertAssociateAsync(associateLogic.MapToSoap(newAssociate)));
            }
            else
            {
                return(false);
            }
        }
Пример #11
0
 public bool Create(AssociateDto associateDto)
 {
     return(_associateDomainService.Create(associateDto));
 }
Пример #12
0
        public async Task <IHttpActionResult> CreateUser(CreateUserBindingModel createUserModel)
        {
            //If the model is valid,
            //We will use it to create
            //a new instance of ApplicationUser
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            //The user's credentials
            //By default, the user
            //will always be level 3
            var user = new ApplicationUser
            {
                UserName  = createUserModel.Username,
                Email     = createUserModel.Email,
                FirstName = createUserModel.FirstName,
                LastName  = createUserModel.LastName,
                Level     = 3,
                JoinDate  = DateTime.Now.Date
            };

            AssociateDto associate = new AssociateDto()
            {
                FirstName = createUserModel.FirstName,
                LastName  = createUserModel.LastName,
                Email     = createUserModel.Email,
                Gender    = createUserModel.Gender,
                //Batch = createUserModel.Batch
            };

            LogicHelper help = new LogicHelper();
            await help.AddNewAssociate(associate);

            //This will do the work for us to create the user
            //It will validate if the username or email has been used before
            //and will let us know if the matches the policy we have set forth
            //If the request is valid, the user will be added to our table in
            //the database and return a successful result
            IdentityResult addUserResult = await this.AppUserManager.CreateAsync(user, createUserModel.Password);


            //If the creation failed
            if (!addUserResult.Succeeded)
            {
                return(GetErrorResult(addUserResult));
            }

            //This will have the token that is valid for 6 hours only when we call this method
            string code = await this.AppUserManager.GenerateEmailConfirmationTokenAsync(user.Id);

            var callbackUrl = new Uri(Url.Link("ConfirmEmailRoute", new { userId = user.Id, code = code }));

            await this.AppUserManager.SendEmailAsync(user.Id, "Confirm Your Account", "Please confirm your account by clicking <a href=\"" + callbackUrl + "\">here</a> <br/> Your password is: " + AutoGenPassword.Generate(8, 10));

            Uri locationHeader = new Uri(Url.Link("GetUserById", new { id = user.Id }));

            //returns the created user
            return(Created(locationHeader, TheModelFactory.Create(user)));
        }
        /// <summary>
        /// After validation, this method will Map the data within the Dto to the Data Layer
        /// </summary>
        public AssociateDao MapToSoap(AssociateDto a)
        {
            var mapper = associateReverseMapper.CreateMapper();

            return(mapper.Map <AssociateDao>(a));
        }