Exemplo n.º 1
0
        public object Register()
        {
            string json = string.Empty;

            try
            {
                var obj = JsonParser.FromJson <RegistrationContext>(Context);

                var user = new User()
                {
                    Username = obj.username,
                    Password = obj.password,
                    Role     = obj.role
                };

                if (GlobalSettings.AdminExists)
                {
                    if (obj.householdId.HasValue)
                    {
                        BusinessLayer.UserBL.Create(obj.householdId.Value, user);
                    }
                    else
                    {
                        BusinessLayer.UserBL.Create(user);
                    }
                }
                else
                {
                    user.Role = BusinessLayer.RoleBL.Get(Constants.Admin);
                    BusinessLayer.UserBL.Create(user);
                }

                if (CurSession.User == null)
                {
                    CurSession.User = user;
                }

                GlobalSettings.CheckForAdmin();

                json = JsonParser.ToJson(user);
            }
            catch (Exception ex)
            {
                json = JsonParser.ExceptionToJson(ex);
            }

            return(json);
        }