Beispiel #1
0
        private async Task <CollaboratorViewModel> FillCollaborator(CollaboratorViewModel collaboratorViewModel)
        {
            var companies = _mapper.Map <IEnumerable <CompanyViewModel> >(await _companyRepository.GetAll());

            collaboratorViewModel.Companies = companies;
            return(collaboratorViewModel);
        }
        public async Task <Response> Update(CollaboratorViewModel model)
        {
            try
            {
                Encoded _encoded = !string.IsNullOrEmpty(model.Password) ? Crypto.EncryptPassword(model.Password) : null;
                var     _entity  = new Collaborator(model);
                _entity.SetActive(true);
                _entity.SetUpdatedAt(DateTime.UtcNow.AddHours(-3));

                if (_encoded != null)
                {
                    _entity.SetPassword(_encoded.Encrypted);
                }

                if (_entity.IsValid())
                {
                    return(Ok(await this._repository.Update(_entity), HttpMessage.Updated_Successfully));
                }
                else
                {
                    return(BadRequest(_entity.GetValidationResults()));
                }
            }
            catch (Exception except)
            {
                return(await InternalServerError(except.Message));
            }
        }
        public async Task <Response> SignIn(CollaboratorViewModel model)
        {
            try
            {
                Collaborator _collaborator = null;
                if (!string.IsNullOrEmpty(model.Email))
                {
                    _collaborator = await this._repository.GetByEmail(model.Email);
                }

                if (_collaborator != null)
                {
                    bool authorized = Crypto.ComparePassword(model.Password, new Encoded(_collaborator.Password));

                    if (authorized)
                    {
                        var _model = this._mapper.Map <CollaboratorViewModel>(_collaborator);
                        var _auth  = new Auth <CollaboratorViewModel>(Jwt.CreateToken(model.Email), _model);
                        return(Ok(_auth, HttpMessage.Login_Authorized));
                    }
                    else
                    {
                        return(Unauthorized("A conta informada é inválida!"));
                    }
                }
                else
                {
                    return(Unauthorized("A conta informada é inválida!"));
                }
            }
            catch (Exception except)
            {
                return(await InternalServerError(except.Message));
            }
        }
Beispiel #4
0
        public CollaboratorViewModel Add(CollaboratorViewModel collaboratorViewModel)
        {
            var collaborator = _mapper.Map <CollaboratorViewModel, Collaborator>(collaboratorViewModel);

            _collaboratorService.Add(collaborator);
            return(collaboratorViewModel);
        }
 public CollaboratorViewModel Update(CollaboratorViewModel collaboratorViewModel)
 {
     _uow.BeginTransaction();
     _collaboratorService.Update(_mapper.Map <CollaboratorViewModel, Collaborator>(collaboratorViewModel));
     _uow.Commit();
     return(collaboratorViewModel);
 }
Beispiel #6
0
        private CollaboratorViewModel MapTo(Collaborator collaborator)
        {
            CollaboratorViewModel collaboratorVM = new CollaboratorViewModel();

            collaboratorVM.IdCommonCongregation = collaborator.IdCommonCongregation;
            collaboratorVM.Name = collaborator.Name;

            collaborator.PhoneNumber = _context.PhoneNumber.Where(p => p.IdCollaborador == collaborator.Id).ToList();

            collaboratorVM.PhoneNumberList      = new List <PhoneNumberViewModel>();
            collaboratorVM.PositionMinistryList = new List <PositionMinistryViewModel>();

            foreach (var phone in collaborator.PhoneNumber)
            {
                var phoneViewModel = new PhoneNumberViewModel();
                phoneViewModel.Id        = phone.Id;
                phoneViewModel.Phone     = phone.Number;
                phoneViewModel.TypePhone = (TypePhone)Enum.Parse(typeof(TypePhone), phone.Type);

                collaboratorVM.PhoneNumberList.Add(phoneViewModel);
            }

            foreach (var positionMinistry in collaborator.PositionMinistryCollaborator)
            {
                var positionMinistryVM = new PositionMinistryViewModel();
                positionMinistryVM.Id          = positionMinistry.IdPositionMinistry;
                positionMinistryVM.Description = _context.PositionMinistry.SingleOrDefault(pm => pm.Id == positionMinistry.IdPositionMinistry).Description;
                collaboratorVM.PositionMinistryList.Add(positionMinistryVM);
            }

            return(collaboratorVM);
        }
Beispiel #7
0
        private Collaborator MapTo(CollaboratorViewModel collaboratorVM)
        {
            Collaborator collaborator = new Collaborator();

            collaborator.IdCommonCongregation = collaboratorVM.IdCommonCongregation;
            collaborator.Name = collaboratorVM.Name;
            collaborator.Id   = collaboratorVM.Id;

            collaborator.PhoneNumber = new List <PhoneNumber>();
            collaborator.PositionMinistryCollaborator = new List <PositionMinistryCollaborator>();

            foreach (var phone in collaboratorVM.PhoneNumberList)
            {
                collaborator.PhoneNumber.Add(new PhoneNumber()
                {
                    Number         = phone.Phone,
                    Type           = phone.TypePhone.ToString(),
                    IdCollaborador = collaboratorVM.Id,
                    Id             = phone.Id
                });
            }

            foreach (var positionMinistry in collaboratorVM.PositionMinistryList)
            {
                collaborator.PositionMinistryCollaborator.Add(new PositionMinistryCollaborator()
                {
                    IdCollaborator     = collaboratorVM.Id,
                    IdPositionMinistry = positionMinistry.Id
                });
            }

            return(collaborator);
        }
Beispiel #8
0
        public CollaboratorViewModel Update(CollaboratorViewModel collaboratorViewModel)
        {
            var collaborator = _mapper.Map <CollaboratorViewModel, Collaborator>(collaboratorViewModel);

            _collaboratorService.Update(collaborator, collaborator.Id);
            return(collaboratorViewModel);
        }
Beispiel #9
0
        [Authorize(Roles = "Admin")]//TODO: RE-ENABLE FOR DEMO
        public ActionResult EditCollaborator(CollaboratorViewModel vm, HttpPostedFileBase file)
        {
            var repo   = RepositoryFactory.CreateRepository();
            var collab = new Collaborator
            {
                CollaboratorId = vm.CollabId,
                Name           = vm.Name,
                Description    = vm.Description,
                //Website = vm.Website,
                Contact = new ContactInfo
                {
                    ContactId     = vm.ContactId,
                    StreetAddress = vm.StreetAddress,
                    City          = vm.City,
                    State         = vm.State,
                    Zip           = vm.Zip,
                    Phone         = vm.Phone,
                    Email         = vm.Email
                }
            };

            collab.ImgPath = file == null ? vm.ImgPath : UploadImage(file);

            repo.EditContact(collab.Contact);
            repo.EditCollaborator(collab);
            return(RedirectToAction("ManageCollaborators", "Admin"));
        }
Beispiel #10
0
        [Authorize(Roles = "Admin")]//TODO: RE-ENABLE FOR DEMO
        public ActionResult EditCollaborator(int id)
        {
            var repo   = RepositoryFactory.CreateRepository();
            var collab = repo.GetCollaboratorById(id);
            var vm     = new CollaboratorViewModel(collab);

            return(View(vm));
        }
Beispiel #11
0
        public async Task <object> ShareCollaborator([FromBody] CollaboratorViewModel model)
        {
            var user = await _userManager.FindByEmailAsync(model.Collaborator);

            if (user.Email == model.Collaborator)
            {
                return(user);
            }
            return(null);
        }
        public CollaboratorViewModel Add(CollaboratorViewModel collaboratorViewModel)
        {
            var collaborator = _mapper.Map <CollaboratorViewModel, Collaborator>(collaboratorViewModel);

            _uow.BeginTransaction();
            var collaboratorReturn = _collaboratorService.Add(collaborator);

            _uow.Commit();

            collaboratorViewModel = _mapper.Map <Collaborator, CollaboratorViewModel>(collaboratorReturn);
            return(collaboratorViewModel);
        }
 public IActionResult Put(long id, [FromBody] CollaboratorViewModel collaborator)
 {
     if (_collaboratorAppService.GetById(collaborator.Id).Id != 0)
     {
         collaborator = _collaboratorAppService.Update(collaborator);
         collaborator.AddRangeLink(_collaboratorEnricher.CreateLinks(Method.Put, collaborator));
         return(Ok(collaborator));
     }
     else
     {
         return(BadRequest());
     }
 }
Beispiel #14
0
        public async Task <IActionResult> Create(CollaboratorViewModel collaboratorViewModel)
        {
            collaboratorViewModel = await FillCollaborator(collaboratorViewModel);

            if (!ModelState.IsValid)
            {
                return(View(collaboratorViewModel));
            }

            var collaborator = _mapper.Map <Collaborator>(collaboratorViewModel);

            await _collaboratorService.Add(collaborator);

            if (!ValidOperation())
            {
                return(View(collaboratorViewModel));
            }

            return(RedirectToAction("Index"));
        }
        public async Task <Response> Save(CollaboratorViewModel model)
        {
            try
            {
                Encoded _encoded = !string.IsNullOrEmpty(model.Password) ? Crypto.EncryptPassword(model.Password) : null;
                var     _entity  = new Collaborator(model);

                _entity.SetActive(true);
                _entity.SetCreatedAt(DateTime.UtcNow.AddHours(-3));

                if (_encoded != null)
                {
                    _entity.SetPassword(_encoded.Encrypted);
                }

                if (_entity.IsValid())
                {
                    var _isExist = await this._repository.GetByEmailAndRegistryCode(_entity.Email, _entity.RegistryCode) == null ? false : true;

                    if (!_isExist)
                    {
                        return(Ok(await this._repository.Save(_entity), HttpMessage.Saved_Successfully));
                    }
                    else
                    {
                        return(AlreadyExists());
                    }
                }
                else
                {
                    return(await ParametersNotProvided(_entity.GetValidationResults()));
                }
            }
            catch (Exception except)
            {
                return(await InternalServerError(except.Message));
            }
        }
Beispiel #16
0
        public async Task <IActionResult> Edit(Guid id, CollaboratorViewModel collaboratorViewModel)
        {
            if (id != collaboratorViewModel.Id)
            {
                return(NotFound());
            }

            if (!ModelState.IsValid)
            {
                return(View(collaboratorViewModel));
            }

            var collaborator = _mapper.Map <Collaborator>(collaboratorViewModel);

            await _collaboratorService.Update(collaborator);

            if (!ValidOperation())
            {
                return(View(_mapper.Map <CollaboratorViewModel>(await _collaboratorRepository.GetById(id))));
            }

            return(RedirectToAction("Index"));
        }
Beispiel #17
0
        public async Task <IActionResult> Create(CollaboratorViewModel collaboratorVM)
        {
            if (ModelState.IsValid)
            {
                Collaborator collaborator = this.MapTo(collaboratorVM);
                _context.Add(collaborator);
                await _context.SaveChangesAsync();

                TempData["Success"] = "Registro inserido com sucesso";
                return(RedirectToAction("Index"));
            }

            ViewBag.CommonList = _context.CommonCongregation.Select(c => new SelectListItem
            {
                Text     = c.Name + " - " + c.CityNavigation.Name,
                Value    = c.Id.ToString(),
                Selected = c.Id == collaboratorVM.IdCommonCongregation
            }).OrderBy(c => c.Text);

            ViewBag.PositionMinistryList = new SelectList(_context.PositionMinistry, "Id", "Description", collaboratorVM.IdPositionMinistry).OrderBy(p => p.Text);
            ViewBag.TypePhoneList        = EnumHelper <TypePhone> .GetSelectListEnum();

            return(View(collaboratorVM));
        }
Beispiel #18
0
        public IEnumerable <Link> CreateLinks(Method method, CollaboratorViewModel content = null)
        {
            var linkContainer = new LinkContainer();

            if (_urlHelper != null)
            {
                var getAll = new Link()
                {
                    Method = "GET", Rel = "get all collaborators pages", Href = _urlHelper.Link("GetAllCollaboratorsPages", new { })
                };
                var insert = new Link()
                {
                    Method = "POST", Rel = "insert collaborator page", Href = _urlHelper.Link("InsertCollaboratorPage", new { })
                };

                var getById = new Link();
                var update  = new Link();
                var delete  = new Link();

                if (content != null)
                {
                    getById = new Link()
                    {
                        Method = "GET", Rel = "get collaborator page by id", Href = _urlHelper.Link("GetCollaboratorPageById", new { id = content.Id })
                    };
                    update = new Link()
                    {
                        Method = "PUT", Rel = "update collaborator page", Href = _urlHelper.Link("UpdateCollaboratorPage", new { id = content.Id })
                    };
                    delete = new Link()
                    {
                        Method = "DELETE", Rel = "delete collaborator page", Href = _urlHelper.Link("DeleteCollaboratorPage", new { id = content.Id })
                    };
                }

                switch (method)
                {
                case Method.GetAll:
                    linkContainer.AddLink(getAll);
                    linkContainer.AddLink(insert);
                    break;

                case Method.Get:
                    linkContainer.AddLink(getById);
                    linkContainer.AddLink(update);
                    linkContainer.AddLink(delete);
                    break;

                case Method.Post:
                    linkContainer.AddLink(insert);
                    linkContainer.AddLink(getById);
                    linkContainer.AddLink(update);
                    linkContainer.AddLink(delete);
                    break;

                case Method.Put:
                    linkContainer.AddLink(update);
                    linkContainer.AddLink(getById);
                    linkContainer.AddLink(delete);
                    break;
                }
                linkContainer.Links[0].Rel = "self";
            }
            return(linkContainer.Links);
        }
Beispiel #19
0
        public async Task <IActionResult> Edit(CollaboratorViewModel collaboratorVM)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    var collaborator = MapTo(collaboratorVM);

                    var oldPhoneNumbersObj = _context.PhoneNumber.AsNoTracking()
                                             .Where(pn => pn.IdCollaborador == collaborator.Id && !collaborator.PhoneNumber.Select(p => p.Id).Contains(pn.Id));

                    var oldPositionMinistryObj = _context.PositionMinistryCollaborator.AsNoTracking()
                                                 .Where(pmc => pmc.IdCollaborator == collaborator.Id && !collaborator.PositionMinistryCollaborator.Select(p => p.Id).Contains(pmc.Id));

                    foreach (var phoneNumber in collaborator.PhoneNumber)
                    {
                        if (phoneNumber.Id == new int())
                        {
                            _context.PhoneNumber.Add(phoneNumber);
                        }
                        else
                        {
                            _context.PhoneNumber.Update(phoneNumber);
                        }
                    }

                    foreach (var oldPhoneNumber in oldPhoneNumbersObj)
                    {
                        _context.PhoneNumber.Remove(oldPhoneNumber);
                    }

                    foreach (var positionMinistry in collaborator.PositionMinistryCollaborator)
                    {
                        if (positionMinistry.Id == new int())
                        {
                            _context.PositionMinistryCollaborator.Add(positionMinistry);
                        }
                        else
                        {
                            _context.PositionMinistryCollaborator.Update(positionMinistry);
                        }
                    }

                    foreach (var oldPositionMinistry in oldPositionMinistryObj)
                    {
                        _context.PositionMinistryCollaborator.Remove(oldPositionMinistry);
                    }

                    _context.Update(collaborator);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!CollaboratorExists(collaboratorVM.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                TempData["Success"] = "Registro alterado com sucesso";
                return(RedirectToAction("Index"));
            }
            ViewBag.CommonList = _context.CommonCongregation.Select(p => new SelectListItem
            {
                Text     = p.Name + "-" + p.CityNavigation.Name,
                Value    = p.Id.ToString(),
                Selected = p.Id == collaboratorVM.IdCommonCongregation
            });

            ViewData["IdPositionMinistry"] = new SelectList(_context.PositionMinistry, "Id", "Description", collaboratorVM.IdPositionMinistry);
            return(View(collaboratorVM));
        }
 public CollaboratorViewModel Post([FromBody] CollaboratorViewModel collaborator)
 {
     collaborator = _collaboratorAppService.Add(collaborator);
     collaborator.AddRangeLink(_collaboratorEnricher.CreateLinks(Method.Post, collaborator));
     return(collaborator);
 }
Beispiel #21
0
 public async Task <IHttpActionResult> Put([FromBody] CollaboratorViewModel model)
 {
     return(Response(await this._service.Update(model)));
 }