Beispiel #1
0
 public ActionResult Create(IndividualViewModel model)
 {
     try
     {
         if (ModelState.IsValid)
         {
             var repository  = new IndividualRepository(context);
             var emailExiste = repository.Query(x => x.Email == model.Email).Count > 0;
             if (!emailExiste)
             {
                 var individual = MapperHelper.Map <Individual>(model);
                 repository.Insert(individual);
                 context.SaveChanges();
             }
             else
             {
                 ModelState.AddModelError("Email", "El correo electrónico esta ocupado");
                 return(View(model));
             }
         }
         return(RedirectToAction("Index"));
     }
     catch
     {
         return(View());
     }
 }
Beispiel #2
0
        public void Topic_ShoulInsertOk()
        {
            var context         = new LearningContext();
            var topicRepository = new TopicRepository(context);

            topicRepository.Insert(new Topic
            {
                Name = "Entity Framework", Descripcion = "Applyling EF6 Data Access Stratagy"
            }
                                   );
            topicRepository.Insert(new Topic
            {
                Name = "Entity Framework2", Descripcion = "Applyling EF6 Data Access Stratagy"
            }
                                   );

            var individual = new IndividualRepository(context);

            individual.Insert(new Individual
            {
                Name = "Benigno", Email = "*****@*****.**"
            }
                              );
            individual.Insert(new Individual
            {
                Name = "Antonio", Email = "*****@*****.**"
            }
                              );
            context.SaveChanges();
        }
Beispiel #3
0
        public ActionResult Create(NewIndividualViewModel model)
        {
            try
            {
                // TODO: Add insert logic here
                if (ModelState.IsValid)
                {
                    var repo = new IndividualRepository(context);

                    var individualQry = new Individual {
                        Email = model.Email
                    };
                    var emailExiste = repo.QueryByExample(individualQry).Count > 0;
                    if (!emailExiste)
                    {
                        var individual = MapperHelpers.Map <Individual>(model);
                        repo.Insert(individual);

                        context.SaveChanges();
                    }
                    else
                    {
                        ModelState.AddModelError("Email", "El Email está ocupado");
                        return(View(model));
                    }
                }

                return(RedirectToAction("Index"));
            }
            catch
            {
                return(View());
            }
        }
Beispiel #4
0
        public ActionResult Details(int id)
        {
            try
            {
                var repo           = new IndividualRepository(context);
                var repoAssignment = new AssignedRepository(context);
                var repoCursos     = new CourseRepository(context);

                var individual  = repo.Find(id);
                var indi        = MapperHelpers.Map <IndividualViewModel>(individual);
                var assginments = repoAssignment.Query(x => x.IndividualId == individual.Id).OrderByDescending(x => x.AssingmentDate).ToList();

                foreach (var item in assginments)
                {
                    var course      = repoCursos.Query(x => x.Id == item.CourseId).ToList();
                    var courseModel = MapperHelpers.Map <ICollection <CoursesViewModel> >(course).SingleOrDefault();
                    indi.Courses.Add(courseModel);
                }

                return(View(indi));
            }
            catch (Exception ex)
            {
                return(RedirectToAction("Index"));
            }
        }
Beispiel #5
0
        public ActionResult Edit(int id, EditIndividualViewModel model)
        {
            try
            {
                var repository = new IndividualRepository(context);
                if (model.Email != model.EmailAnterior)
                {
                    var existeEmail = repository.Query(x => x.Email == model.Email && x.Id != model.Id).Count > 0;
                    if (existeEmail)
                    {
                        ModelState.AddModelError("Email", "Email ocupado");
                        return(View(model));
                    }
                }
                else
                {
                    ModelState.Remove("Email");
                }

                if (ModelState.IsValid)
                {
                    var individual = MapperHelper.Map <Individual>(model);
                    repository.Update(individual);
                    context.SaveChanges();
                }
                return(RedirectToAction("Index"));
            }
            catch
            {
                return(View());
            }
        }
Beispiel #6
0
        public ActionResult Create(NewIndividualViewModel model)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    var repository    = new IndividualRepository(context);
                    var individualQry = new Individual {
                        Email = model.Email
                    };
                    var emailExiste = repository.QueryByExample(individualQry).Count > 0;
                    if (!emailExiste)
                    {
                        var individual = MapperHelper.Map <Individual>(model);
                        repository.Insert(individual);
                        context.SaveChanges();
                    }
                    else
                    {
                        ModelState.AddModelError("Email", "El email está ocupado");
                        return(View(model));
                    }
                }

                return(RedirectToAction("Index"));
            }
            catch (Exception ex)
            {
                ViewBag.Error = ex.Message;
                return(View());
            }
        }
 public ContragentController(IConfiguration configuration)
 {
     contragentRepository   = new ContragentRepository(configuration);
     organizationRepository = new OrganizationRepository(configuration);
     individualRepository   = new IndividualRepository(configuration);
     documentRepository     = new DocumentRepository(configuration);
 }
Beispiel #8
0
        public JsonResult CheckEmail(string email)
        {
            var repository  = new IndividualRepository(context);
            var emailExiste = repository.Query(x => x.Email == email).Count == 0;

            return(Json(emailExiste, JsonRequestBehavior.AllowGet));
        }
        public IndividualController()
        {
            string connectionString = Settings.GetStringDB();

            _individRepository = new IndividualRepository(connectionString);
            ur = new UserRepository(connectionString);
            _roleRepository = new RoleRepository(connectionString);
        }
Beispiel #10
0
        // GET: Invidivual
        public ActionResult Index()
        {
            var repository  = new IndividualRepository(context);
            var individuals = repository.GetAll();
            var model       = MapperHelpers.Map <IEnumerable <IndividualViewModel> >(individuals);

            return(View(model));
        }
Beispiel #11
0
        // GET: individual
        public ActionResult Index()
        {
            var repository = new IndividualRepository(context);
            var entities   = repository.GetAll();
            var results    = MapperHelper.mapper.Map <ICollection <IndividualViewModel> >(entities);

            return(View(results));
        }
Beispiel #12
0
        // GET: Invidivual/Edit/5
        public ActionResult Edit(int id)
        {
            var repo       = new IndividualRepository(context);
            var model      = repo.Find(id);
            var individual = MapperHelpers.Map <EditIndividualViewModel>(model);

            return(View(individual));
        }
Beispiel #13
0
        // GET: Individual/Details/5
        public ActionResult Details(int id)
        {
            var repository = new IndividualRepository(context);
            var individual = repository.Find(id);
            var model      = MapperHelper.Map <IndividualViewModel>(individual);

            return(View(model));
        }
Beispiel #14
0
        // GET: individual/Delete/5
        public ActionResult Delete(int id)
        {
            var repository = new IndividualRepository(context);
            var entity     = repository.Find(id);
            var model      = MapperHelper.Map <IndividualViewModel>(entity);

            context.SaveChanges();
            return(View(model));
        }
Beispiel #15
0
        // GET: Individual
        /// <summary>
        /// Lista de individuals y se la va a pasar a la vista Index
        /// </summary>
        /// <returns></returns>
        public ActionResult Index()
        {
            ViewBag.Title = "Individual List";
            var repository  = new IndividualRepository(context);
            var individuals = repository.GetAll();
            var models      = MapperHelper.Map <IEnumerable <IndividualViewModel> >(individuals);

            return(View(models));
        }
Beispiel #16
0
        // GET: individual/Edit/5
        public ActionResult Edit(int id)
        {
            var repository = new IndividualRepository(context);
            var entity     = repository.Find(id);
            var model      = MapperHelper.Map <IndividualViewModel>(entity);

            ModelState.Remove("Email");
            return(View(model));
        }
Beispiel #17
0
        // GET: Individual/Edit/5
        public ActionResult Edit(int id)
        {
            var repositorio = new IndividualRepository(context);
            var individual  = repositorio.Find(id);
            var model       = MapperHelper.Map <EditIndividualViewModel>(individual);

            model.EmailAnterior = model.Email;
            return(View(model));
        }
        public bool AuthenticateIndividual(Credentials credentials)
        {
            var principal = IndividualRepository.GetIndividualCredentialsByUsername(credentials.Username);

            if (principal == null)
            {
                return(false);
            }
            return(SlowEquals(principal.Password, HashPassword(credentials.Password, principal.Salt)));
        }
Beispiel #19
0
        /// <summary>
        /// Default constructor
        /// </summary>
        public IndividualListModel()
        {
            if (_individualRepository == null)
            {
                _individualRepository = new IndividualRepository();
            }

            AllIndividuals  = new ObservableCollection <Individual>(_individualRepository.GetIndividuals());
            _individualList = new ObservableCollection <Individual>(_individualRepository.GetIndividuals());
        }
        public SelectList PopulateInviduals(object selectedItem = null)
        {
            var repository  = new IndividualRepository(context);
            var individuals = repository.Query(null, "Name").ToList();

            individuals.Insert(0, new Individual {
                Id = null, Name = "Seleccione"
            });
            return(new SelectList(individuals, "Id", "Name", selectedItem));
        }
        public ActionResult <IndividualDto> GetAccountData()
        {
            var individualID = new JwtSecurityToken(Request.Cookies["token"]).Claims.First(c => c.Type == "aud").Value;
            var individual   = IndividualRepository.GetIndividualByID(Guid.Parse(individualID));

            if (individual.HasNoValue)
            {
                return(NoContent());
            }
            return(Ok(Mapper.Map <IndividualDto>(individual.Value)));
        }
Beispiel #22
0
 public UnitOfWork(ApplicationDbContext context)
 {
     _context            = context;
     Individuals         = new IndividualRepository(context);
     BankAccounts        = new BankAccountRepository(context);
     Requests            = new RequestRepository(context);
     Users               = new ApplicationUserRepository(context);
     BankAccountTypes    = new BankAccountTypeRepository(context);
     BankAccountRequests = new BankAccountRequestRepository(context);
     Transactions        = new TransactionsRepository(context);
     TransactionTypes    = new TransactionTypeRepository(context);
 }
Beispiel #23
0
        // GET: Individual
        public ActionResult Index()
        {
            var repository = new IndividualRepository(context);
            var individual = repository.GetAll();

            /*var model = individual.Select(x => new IndividualViewModel
             * { Id = x.Id, Name = x.Name, Email = x.Email }
             * ).ToList();*/
            var model = MapperHelper.Map <IEnumerable <IndividualViewModel> >(individual);

            return(View(model));
        }
        public ActionResult <IndividualConfirmationDto> CreateIndividual(IndividualCreationDto businessDto)
        {
            var individual     = Mapper.Map <Individual>(businessDto);
            var hashedPassword = AuthenticationHelper.HashPassword(individual.Password);

            individual.Password = hashedPassword.Item1;
            individual.Salt     = hashedPassword.Item2;
            IndividualConfirmationDto individualConfirmation = IndividualRepository.CreateIndividual(individual);

            IndividualRepository.SaveChanges();
            return(Created("", individualConfirmation));
        }
Beispiel #25
0
 public ActionResult Delete(int id, FormCollection collection)
 {
     try
     {
         var repository = new IndividualRepository(context);
         var entity     = repository.Find(id);
         repository.Delete(entity);
         context.SaveChanges();
         return(RedirectToAction("Index"));
     }
     catch
     {
         return(View(new IndividualViewModel()));
     }
 }
Beispiel #26
0
 public ActionResult Delete(int id, IndividualViewModel model)
 {
     try
     {
         var repository = new IndividualRepository(context);
         var individual = MapperHelper.Map <Individual>(model);
         repository.Delete(individual);
         context.SaveChanges();
         return(RedirectToAction("Index"));
     }
     catch
     {
         return(View());
     }
 }
Beispiel #27
0
 public ActionResult Edit(int id, IndividualViewModel model)
 {
     try
     {
         var repository = new IndividualRepository(context);
         ModelState.Remove("Email");
         var entity = MapperHelper.Map <Individual>(model);
         repository.Update(entity);
         context.SaveChanges();
         return(RedirectToAction("Index"));
     }
     catch
     {
         return(View(new IndividualViewModel()));
     }
 }
Beispiel #28
0
 // GET: Individual
 /// <summary>
 /// Lista de individuals y se la va a pasar a la vista Index
 /// </summary>
 /// <returns></returns>
 public ActionResult Index()
 {
     try
     {
         var repository  = new IndividualRepository(context);
         var individuals = repository.GetAll();
         var models      = MapperHelper.Map <IEnumerable <IndividualViewModel> >(individuals);
         return(View(models));
     }
     catch (Exception ex)
     {
         var model = new IndividualViewModel();
         ViewBag.ErrorMessage = ex.Message;
         return(View(model));
     }
 }
Beispiel #29
0
        public ActionResult Delete(int id, IndividualViewModel model)
        {
            try
            {
                var repo = new IndividualRepository(context);
                //if (ModelState.IsValid)
                //{
                var individual = MapperHelpers.Map <Individual>(model);
                repo.Delete(individual);
                context.SaveChanges();
                //}
                // TODO: Add delete logic here

                return(RedirectToAction("Index"));
            }
            catch
            {
                return(View());
            }
        }
        public ActionResult <IndividualDto> UpdateIndividual(IndividualUpdateDto individualDto)
        {
            var oldIndividual = IndividualRepository.GetIndividualByID(individualDto.Id).Value;

            if (oldIndividual == null)
            {
                return(NotFound());
            }
            var pass = AuthenticationHelper.HashPassword(individualDto.Password);

            oldIndividual.LastName    = individualDto.LastName;
            oldIndividual.FirstName   = individualDto.FirstName;
            oldIndividual.Email       = individualDto.Email;
            oldIndividual.Username    = individualDto.Username;
            oldIndividual.PhoneNumber = individualDto.PhoneNumber;
            oldIndividual.Salt        = pass.Item2;
            oldIndividual.Password    = pass.Item1;
            IndividualRepository.SaveChanges();
            return(Ok(Mapper.Map <IndividualDto>(oldIndividual)));
        }