public async Task <IActionResult> Create([Bind("id,profile_id,medication,dosage,physician,last_dose,taking_as_prescribed,created_at,created_by")] mp_medication mp_medication)
        {
            if (ModelState.IsValid)
            {
                _context.Add(mp_medication);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["profile_id"] = new SelectList(_context.mp_profile, "id", "first_name", mp_medication.profile_id);
            return(View(mp_medication));
        }
Beispiel #2
0
        public int AddPediatricEvaluation(mp_pediatric_evaluation evaluation)
        {
            var old = _context.mp_pediatric_evaluation.FirstOrDefault(e => e.appointment_id == evaluation.appointment_id && e.profile_id == evaluation.profile_id);

            if (old == null)
            {
                _context.Add(evaluation);
            }
            else
            {
                evaluation.created_by   = old.created_by;
                evaluation.created_date = old.created_date;
                evaluation.id           = old.id;

                _context.Entry(old).CurrentValues.SetValues(evaluation);
            }
            _context.SaveChanges();

            return(evaluation.id);
        }
Beispiel #3
0
 public int AddPsychosocial(mp_psychosocial psychosocial)
 {
     _context.Add(psychosocial);
     return(_context.SaveChanges());
 }
Beispiel #4
0
        public UserModel SaveUser(UserModel user)
        {
            try
            {
                using (HContext dbContext = new HContext())
                {
                    UserModel exUser = null;
                    if (user.Id > 0)
                    {
                        exUser = dbContext.Users.Where(a => a.UserName == user.UserName && a.Id != user.Id).FirstOrDefault();
                    }
                    else
                    {
                        exUser = dbContext.Users.Where(a => a.RealName == user.RealName || a.UserName == user.UserName).FirstOrDefault();
                    }
                    if (exUser != null)
                    {
                        user.ErrorCode = -1;
                        user.ErrorMsg  = "用户名已存在,请更换后再保存。";
                        return(user);
                    }
                    if (user.Id > 0)
                    {
                        UserModel preUser = dbContext.Users.Include("Roles").Where(a => a.Id == user.Id).First();
                        preUser.PositionId   = user.PositionId;
                        preUser.PositionName = user.PositionName;
                        //preUser.Code = user.Code;
                        preUser.UserName     = user.UserName;
                        preUser.RealName     = user.RealName;
                        preUser.Phone        = user.Phone;
                        preUser.Sex          = user.Sex;
                        preUser.DeptId       = user.DeptId;
                        preUser.DeptName     = user.DeptName;
                        preUser.PositionId   = user.PositionId;
                        preUser.PositionName = user.PositionName;
                        preUser.StoreId      = user.StoreId;
                        preUser.StoreName    = user.StoreName;
                        preUser.Status       = user.Status;
                        preUser.RoleIds      = user.RoleIds;
                        preUser.EntryDate    = user.EntryDate;
                        preUser.Cover        = user.Cover;
                        UserModel u = dbContext.Users.Include("Roles").Where(a => a.Id == user.Id).First();
                        if (user != null)
                        {
                            IList <RoleModel> roles = new List <RoleModel>();
                            if (user.RoleIds != null && user.RoleIds.Count > 0)
                            {
                                roles = dbContext.Roles.Where(a => user.RoleIds.Contains(a.Id)).ToList();
                            }
                            user.Roles    = roles;
                            preUser.Roles = roles;

                            bool flag = dbContext.SaveChanges() > 0;
                        }
                        //dbContext.Update(user);
                    }
                    else
                    {
                        IList <RoleModel> roles = new List <RoleModel>();
                        if (user.RoleIds != null && user.RoleIds.Count > 0)
                        {
                            roles = dbContext.Roles.Where(a => user.RoleIds.Contains(a.Id)).ToList();
                        }
                        user.Roles = roles;


                        Random ran  = new Random();
                        int    num  = ran.Next(1000, 9999);
                        string code = num.ToString();

                        UserModel userM = dbContext.Users.Where(a => a.Code == code).FirstOrDefault();
                        while (userM != null)
                        {
                            num   = ran.Next(1000, 9999);
                            code  = num.ToString();
                            userM = dbContext.Users.Where(a => a.Code == code).FirstOrDefault();
                        }
                        user.Code = code;
                        dbContext.Add(user);
                    }
                    return(user);
                }
            }
            catch (Exception ex)
            {
                user.ErrorCode = -1;
                user.ErrorMsg  = ex.Message;
                return(user);
            }
        }
Beispiel #5
0
 public async Task <int> AddProgressNote(mp_progress_note note)
 {
     _context.Add(note);
     return(await _context.SaveChangesAsync());
 }
Beispiel #6
0
 public async Task <int> Add(mp_psychiatric_progress_note progess_note)
 {
     _context.Add(progess_note);
     return(await _context.SaveChangesAsync());
 }
 public async Task <int> AddSocialRelationship(mp_social_relationship relationship)
 {
     _context.Add(relationship);
     return(await _context.SaveChangesAsync());
 }
Beispiel #8
0
 public async Task<int> AddLookUp(mp_lookup lookup)
 {
     _context.Add(lookup);
     return await _context.SaveChangesAsync();
 }
Beispiel #9
0
 //adds mp_substance_use to the db
 public async Task <int> AddSubstanceUse(mp_substance_use substance_use)
 {
     _context.Add(substance_use);
     return(await _context.SaveChangesAsync());
 }