private bool UpdateActiveUserRoleIn_DB(AppUserDetailsVM user)
        {
            ActiveRole activeRole = _context.ActiveRoles.FirstOrDefault(ar => ar.UserId == user.Id);

            if (activeRole is null)
            {
                //## User First time Switched Role (as a Doctor)
                activeRole = new ActiveRole()
                {
                    OrganisationId = (user.ApplicationRole == ApplicationRole.Patient ? 0 : user.CurrentRole.OrganisationId),
                    UserId         = user.Id,
                    RoleId         = (int)user.ApplicationRole
                };

                _context.ActiveRoles.Add(activeRole);
            }
            else
            {
                activeRole.OrganisationId = user.CurrentRole.OrganisationId;
                activeRole.RoleId         = (int)user.ApplicationRole;

                _context.ActiveRoles.Update(activeRole);
            }

            _context.SaveChangesAsync();

            return(true);
        }
Ejemplo n.º 2
0
        public ActionResult AjaxForm()
        {
            var activeRole = new ActiveRole();

            if (DoAction == ActionType.Edit)
            {
                activeRole = _activeRoleDa.GetById(ArrId.FirstOrDefault());
            }

            ViewData.Model     = activeRole;
            ViewBag.Action     = DoAction;
            ViewBag.ActionText = ActionText;
            return(View());
        }
Ejemplo n.º 3
0
        public bool InitData()
        {
            SqlConnection sql = new SqlConnection(ConnectionString);

            listFactory.Clear();
            listHour.Clear();
            listPlanDocType.Clear();
            listRP.Clear();
            listForecastDocType.Clear();

            try
            {
                sql.Open();
            }
            catch (Exception exc)
            {
                exception = exc;
                return(false);
            }
            try
            {
                SqlCommand cmd = new SqlCommand();
                cmd.Connection = sql;
                SqlDataReader reader = null;

                if (ActiveRole.Contains("energy"))
                {
                    cmd.CommandText = string.Format("SELECT RPID, RPName FROM {0}.RP", ActiveSchema);
                    reader          = cmd.ExecuteReader();
                    while (reader.Read())
                    {
                        listRP[reader.GetInt32(0)] = reader.GetString(1).Trim();
                    }
                    reader.Close();

                    cmd.CommandText = string.Format("SELECT DocTypeID, DocTypeName FROM dbo.ForecastDocumentType");
                    reader          = cmd.ExecuteReader();
                    while (reader.Read())
                    {
                        listForecastDocType[reader.GetInt32(0)] = reader.GetString(1).Trim();
                    }
                    reader.Close();
                }

                cmd.CommandText = string.Format("SELECT FactoryID, FactoryName FROM {0}.Factory", ActiveSchema);
                reader          = cmd.ExecuteReader();
                while (reader.Read())
                {
                    listFactory[reader.GetInt32(0)] = reader.GetString(1).Trim();
                }
                reader.Close();
                cmd.CommandText = "SELECT HourID, HourName FROM dbo.HourTable";
                reader          = cmd.ExecuteReader();
                while (reader.Read())
                {
                    listHour[reader.GetInt32(0)] = reader.GetString(1).Trim();
                }
                reader.Close();
                cmd.CommandText = string.Format("SELECT ProductID, ProductName, GroupID FROM {0}.Product", ActiveSchema);
                reader          = cmd.ExecuteReader();
                while (reader.Read())
                {
                    if (!productGroups.ContainsKey(reader.GetInt32(2)))
                    {
                        productGroups[reader.GetInt32(2)] = new Dictionary <int, string>();
                    }
                    productGroups[reader.GetInt32(2)][reader.GetInt32(0)] = reader.GetString(1).Trim();
                }

                reader.Close();
                cmd.CommandText = "SELECT DocTypeID, DocTypeName FROM dbo.DocumentType";
                reader          = cmd.ExecuteReader();
                while (reader.Read())
                {
                    listPlanDocType[reader.GetInt32(0)] = reader.GetString(1).Trim();
                }
                reader.Close();
            }
            catch (Exception exc)
            {
                exception = exc;
                return(false);
            }
            sql.Close();
            return(true);
        }
Ejemplo n.º 4
0
 /// <summary>
 /// Xóa bản ghi
 /// </summary>
 public void Delete(ActiveRole activeRole)
 {
     FDIDB.ActiveRoles.Remove(activeRole);
 }
Ejemplo n.º 5
0
 /// <summary>
 /// Thêm mới bản ghi
 /// </summary>
 /// <param name="activeRole">bản ghi cần thêm</param>
 public void Add(ActiveRole activeRole)
 {
     FDIDB.ActiveRoles.Add(activeRole);
 }
Ejemplo n.º 6
0
        public ActionResult Actions()
        {
            var msg        = new JsonMessage();
            var activeRole = new ActiveRole();

            switch (DoAction)
            {
            case ActionType.Add:
                try
                {
                    UpdateModel(activeRole);
                    _activeRoleDa.Add(activeRole);
                    _activeRoleDa.Save();
                    msg = new JsonMessage
                    {
                        Erros   = false,
                        ID      = activeRole.Id.ToString(),
                        Message =
                            string.Format("Đã thêm mới hành động: <b>{0}</b>",
                                          Server.HtmlEncode(activeRole.NameActive))
                    };
                }
                catch (Exception ex)
                {
                    LogHelper.Instance.LogError(GetType(), ex);
                }
                break;

            case ActionType.Edit:
                try
                {
                    activeRole = _activeRoleDa.GetById(ArrId.FirstOrDefault());
                    UpdateModel(activeRole);
                    _activeRoleDa.Save();
                    msg = new JsonMessage
                    {
                        Erros   = false,
                        ID      = activeRole.Id.ToString(),
                        Message = string.Format("Đã cập nhật chuyên mục: <b>{0}</b>", Server.HtmlEncode(activeRole.NameActive))
                    };
                }
                catch (Exception ex)
                {
                    LogHelper.Instance.LogError(GetType(), ex);
                }
                break;

            case ActionType.Delete:
                var ltsRolesItems = _activeRoleDa.GetListByArrID(ArrId);
                var stbMessage    = new StringBuilder();
                foreach (var item in ltsRolesItems)
                {
                    if (item.aspnet_Roles.Count > 0)
                    {
                        stbMessage.AppendFormat("Chuyên mục <b>{0}</b> đang được sử dụng, không được phép xóa.<br />", Server.HtmlEncode(item.NameActive));
                        //msg.Erros = true;
                    }
                    else
                    {
                        _activeRoleDa.Delete(item);
                        stbMessage.AppendFormat("Đã xóa chuyên mục <b>{0}</b>.<br />", Server.HtmlEncode(item.NameActive));
                    }
                }
                msg.ID = string.Join(",", ArrId);
                _activeRoleDa.Save();
                msg.Message = stbMessage.ToString();
                break;
            }

            if (string.IsNullOrEmpty(msg.Message))
            {
                msg.Message = "Không có hành động nào được thực hiện.";
                msg.Erros   = true;
            }

            return(Json(msg, JsonRequestBehavior.AllowGet));
        }