Exemplo n.º 1
0
 public void SaveAllaergytList(int UserId, List <int> AllergyListIds)
 {
     AllergyListIds.ForEach(a => {
         MedicationAllergyMap map = new MedicationAllergyMap
         {
             UserId    = UserId,
             AllergyId = a,
         };
         _context.Set <MedicationAllergyMap>().Add(map);
         _context.SaveChanges();
     });
 }
Exemplo n.º 2
0
        public ActionResult SaveAllergyByUserId([FromBody] List <int> AllergyListIds)
        {
            APIJsonResult result = new APIJsonResult();
            //if (AllergyListIds.Count() < 1)
            //{
            //    result.success = false;
            //    result.Msg.Add("PatientAllergyEmpty");
            //    return Ok(result);
            //}
            var userId = User.Claims.SingleOrDefault(x => x.Type == "UserId") != null?User.Claims.SingleOrDefault(x => x.Type == "UserId").Value : null;

            int UserId = 0;

            Int32.TryParse(userId, out UserId);
            if (UserId == 0)
            {
                result.success = false;
                result.Msg.Add("NoUser");
                return(Ok(result));
            }
            result.success = true;
            result.Access  = true;

            _medicationAllergyMap.Where(a => a.UserId == UserId).ToList().ForEach(a =>
            {
                _medicationAllergyMap.Remove(a);
                _context.SaveChanges();
            });
            if (AllergyListIds != null)
            {
                AllergyListIds.ForEach(a =>
                {
                    MedicationAllergyMap model = new MedicationAllergyMap();
                    model.UserId    = UserId;
                    model.AllergyId = a;
                    _medicationAllergyMap.Add(model);
                    _context.SaveChanges();
                });
            }

            //_allergyRepository.SaveAllaergytList(UserId, AllergyListIds);
            return(Ok(result));
        }