Exemple #1
0
        private async Task CheckPreventAsync(PreventTypeEntity Consejo, PreventTypeEntity Guia, UserEntity Admin)
        {
            if (!_dataContext.Prevents.Any())
            {
                _dataContext.Prevents.Add(new PreventEntity
                {
                    Title         = "ALCOHOL CONSUMPTION",
                    Description   = "The greater amount of alcohol you consume, the higher risk you have of breast cancer.",
                    Date          = DateTime.UtcNow,
                    PreventTypeId = Consejo.Id,
                    PreventType   = Consejo,
                    File          = "~/images/prevents/11c52af4-1311-47bb-98b3-91a8334f3590.jpg",
                    User          = Admin
                });

                _dataContext.Prevents.Add(new PreventEntity
                {
                    Title         = "CONTROL WEIGHT",
                    Description   = "Fat and obesity increase the risk of breast cancer and even more so when they occur at an older age, particularly after menopause.",
                    Date          = DateTime.UtcNow,
                    PreventTypeId = Guia.Id,
                    PreventType   = Guia,
                    File          = "~/images/prevents/46da3641-08ae-457d-9c2b-ca7d2cd61be7.jpg",
                    User          = Admin
                });
                await _dataContext.SaveChangesAsync();
            }
        }
        public async Task <IActionResult> Create(PreventTypeEntity preventTypeEntity)
        {
            if (ModelState.IsValid)
            {
                _context.Add(preventTypeEntity);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(preventTypeEntity));
        }
        public async Task <IActionResult> Edit(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            PreventTypeEntity preventTypeEntity = await _context.PreventTypes.FindAsync(id);

            if (preventTypeEntity == null)
            {
                return(NotFound());
            }
            return(View(preventTypeEntity));
        }
        public async Task <IActionResult> Edit(int id, PreventTypeEntity preventTypeEntity)
        {
            if (id != preventTypeEntity.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                _context.Update(preventTypeEntity);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(preventTypeEntity));
        }
        public async Task <IActionResult> Details(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            PreventTypeEntity preventTypeEntity = await _context.PreventTypes.FindAsync(id);

            //    .FirstOrDefaultAsync(m => m.Id == id);
            if (preventTypeEntity == null)
            {
                return(NotFound());
            }

            return(View(preventTypeEntity));
        }
 public PreventTypeResponse ToPreventResponse(PreventTypeEntity preventEntity)
 {
     return(new PreventTypeResponse
     {
         Id = preventEntity.Id,
         Name = preventEntity.Name,
         Prevents = preventEntity.Prevents?.Select(t => new PreventResponse
         {
             Id = t.Id,
             Title = t.Title,
             Description = t.Description,
             Date = t.Date,
             User = ToUserResponse(t.User),
             File = t.File
         }).ToList()
     });
 }