public ActionResult Create([Bind(Include = "ServiceId,Category1Id,Category2Id,Category3Id,Category4Id,ImpactId,Contact,Title,Description")] CreateRequestViewModel createRequestUserViewModel)
        {
            RequestBuilder builder = new RequestBuilder();

            ActiveDirectoryReadOnlyRepository ad = new ActiveDirectoryReadOnlyRepository();
            ActiveDirectoryUser adu = ad.GetUser(HttpContext.User.Identity.Name);

            User user;

            user = unitOfWork.UserRepository.GetUserBySamAccountName(HttpContext.User.Identity.Name);
            if (user == null)
            {
                UserName un = new UserName(adu.Name, adu.Surname);
                user = new User(un, adu.SamAccountName, adu.EmailAddress, "");
            }
            else
            {
                user.mail = adu.EmailAddress;
            }

            builder.WithWhoRegistered(user);
            builder.WithOwner(user);

            Origin origin = unitOfWork.OriginRepository.GetOriginByName("Aplicação");

            builder.WithOrigin(origin);
            builder.WithContact(createRequestUserViewModel.Contact);

            Category category;

            if (createRequestUserViewModel.Category4Id < 1)
            {
                if (createRequestUserViewModel.Category3Id < 1)
                {
                    if (createRequestUserViewModel.Category2Id < 1)
                    {
                        if (createRequestUserViewModel.Category1Id < 1)
                        {
                        }
                        else
                        {
                            category = unitOfWork.CategoryRepository.Get(createRequestUserViewModel.Category1Id);
                            builder.WithCategory(category);
                        }
                    }
                    else
                    {
                        category = unitOfWork.CategoryRepository.Get(createRequestUserViewModel.Category2Id);
                        builder.WithCategory(category);
                    }
                }
                else
                {
                    category = unitOfWork.CategoryRepository.Get(createRequestUserViewModel.Category3Id);
                    builder.WithCategory(category);
                }
            }
            else
            {
                category = unitOfWork.CategoryRepository.Get(createRequestUserViewModel.Category4Id);
                builder.WithCategory(category);
            }

            Impact impact = unitOfWork.ImpactRepository.Get(createRequestUserViewModel.ImpactId);

            builder.WithContact(createRequestUserViewModel.Contact);

            builder.WithImpact(impact);

            builder.WithTitle(createRequestUserViewModel.Title);
            builder.WithDescription(HttpUtility.HtmlDecode(createRequestUserViewModel.Description));

            Service            service            = unitOfWork.ServiceRepository.Get(createRequestUserViewModel.ServiceId);
            InteractionBuilder interactionBuilder = new InteractionBuilder();

            interactionBuilder.WithTitle(createRequestUserViewModel.Title);
            interactionBuilder.WithService(service);
            Interaction interaction = interactionBuilder.Build();

            Request request = builder.Build();

            request.AddInteraction(interaction);

            unitOfWork.RequestRepository.Insert(request);
            unitOfWork.SaveChanges();

            MailService ms = new MailService();

            ms.CreateMail("Assunto", "Corpo");
            MailAddress mail = new MailAddress(user.mail);

            ms.AddMail(mail);
            ms.Send();

            return(RedirectToAction("Index", "Home"));
        }
        public ActionResult Create([Bind(Include = "OriginId,ServiceId,Category1Id,Category2Id,Category3Id,Category4Id,ImpactId,Contact,Title,Description")] CreateRequestViewModel createRequestViewModel)
        {
            RequestBuilder builder = new RequestBuilder();

            User user1 = unitOfWork.UserRepository.Get(1);
            User user2 = unitOfWork.UserRepository.Get(2);

            builder.WithWhoRegistered(user1);
            builder.WithOwner(user2);

            Origin origin = unitOfWork.OriginRepository.Get(createRequestViewModel.OriginId);

            builder.WithOrigin(origin);

            Category category;

            if (createRequestViewModel.Category4Id < 1)
            {
            }
            else
            {
                category = unitOfWork.CategoryRepository.Get(createRequestViewModel.Category4Id);
                builder.WithCategory(category);
            }
            if (createRequestViewModel.Category3Id < 1)
            {
            }
            else
            {
                category = unitOfWork.CategoryRepository.Get(createRequestViewModel.Category3Id);
                builder.WithCategory(category);
            }
            if (createRequestViewModel.Category2Id < 1)
            {
            }
            else
            {
                category = unitOfWork.CategoryRepository.Get(createRequestViewModel.Category2Id);
                builder.WithCategory(category);
            }
            if (createRequestViewModel.Category1Id < 1)
            {
            }
            else
            {
                category = unitOfWork.CategoryRepository.Get(createRequestViewModel.Category1Id);
                builder.WithCategory(category);
            }

            Impact impact = unitOfWork.ImpactRepository.Get(createRequestViewModel.ImpactId);

            builder.WithImpact(impact);

            builder.WithContact(createRequestViewModel.Contact);

            builder.WithTitle(createRequestViewModel.Title);

            builder.WithDescription(createRequestViewModel.Description);

            Service service = unitOfWork.ServiceRepository.Get(createRequestViewModel.ServiceId);

            InteractionBuilder interactionBuilder = new InteractionBuilder();

            interactionBuilder.WithTitle(createRequestViewModel.Title);
            interactionBuilder.WithService(service);
            Interaction interaction = interactionBuilder.Build();

            Request request = builder.Build();

            request.AddInteraction(interaction);

            unitOfWork.RequestRepository.Insert(request);
            unitOfWork.SaveChanges();

            return(RedirectToAction("Index", "Home"));
        }