Beispiel #1
0
        public String canActivate(Permissions has, Permissions need)
        {
            foreach (var needp in need)
            {
                foreach (var hasp in has)
                {
                    if (!ContextUtils.matchesToMask(hasp.getEntity(), needp.getEntity(), true, false))
                    {
                        continue;
                    }
                    if (haveType(hasp.getType(), needp.getType()))
                    {
                        continue;
                    }
                    if (!haveType(getType(has, needp.getEntity()), needp.getType()))
                    {
                        return("Cannot set permissions for '" + needp.getEntity() + "' to '" + needp.getType() +
                               "' because your own permission level for '" + hasp.getEntity() + "' is '" +
                               hasp.getType() + "'");
                    }
                }
            }

            return(null);
        }
Beispiel #2
0
 public ActionResult ForgottenPasswordConfirm(string code)
 {
     try
     {
         using (var dataContext = new HuntingEntities())
         {
             int languageId = (int)Session[LocalizationAttribute.SESSION_LANGUAGE_ID];
             if (string.IsNullOrWhiteSpace(User.Identity.Name) == false)
             {
                 ContextUtils.CreateActionStateCookie(Response, ActionTypeEnum.Warning, GlobalRes.ERROR_NOT_ALLOWED);
                 return(RedirectToAction("Index", "Home"));
             }
             var aclUser = AclUserContext.GetDetailByEmailCode(dataContext, code);
             if (aclUser == null)
             {
                 ContextUtils.CreateActionStateCookie(Response, ActionTypeEnum.Warning, AccountRes.ERROR_CODE_INVALID);
                 return(RedirectToAction("Index", "Home"));
             }
             if (aclUser.AccountTypeEx == AccountTypeEnum.Admin)
             {
                 ContextUtils.CreateActionStateCookie(Response, ActionTypeEnum.Warning, AccountRes.ERROR_FORGOTTEN_PASSWORD_ADMIN);
                 return(RedirectToAction("Index", "Home"));
             }
             var model = new ChangePasswordModel(aclUser);
             return(View(model));
         }
     }
     catch (Exception exception)
     {
         logger.Error(exception, "AccountController");
         ContextUtils.CreateActionStateCookie(Response, ActionTypeEnum.Danger, GlobalRes.ERROR_EXCEPTION);
         return(RedirectToAction("Index", "Home"));
     }
 }
Beispiel #3
0
        /// <summary>
        /// Method that performs actually performs the work.
        /// </summary>
        protected override void PerformWork()
        {
            try
            {
                var testCommand = MakeTestCommand();

                // Isolate the Execute call because the WorkItemComplete below will run one-time teardowns. Execution
                // context values should not flow from a particular test case into the shared one-time teardown.
                Result = ContextUtils.DoIsolated(() => testCommand.Execute(Context));
            }
            catch (Exception ex)
            {
                // Currently, if there are no command wrappers, test
                // actions, setup or teardown, we have to catch any
                // exception from the test here. In addition, since
                // users may create their own command wrappers, etc.
                // we have to protect against unhandled exceptions.

#if THREAD_ABORT
                if (ex is ThreadAbortException)
                {
                    Thread.ResetAbort();
                }
#endif

                Context.CurrentResult.RecordException(ex);
                Result = Context.CurrentResult;
            }
            finally
            {
                WorkItemComplete();
            }
        }
Beispiel #4
0
 // GET: Admin
 public ActionResult Index(AclUserFilter filter, int?page)
 {
     try
     {
         using (var dataContext = new HuntingEntities())
         {
             int languageId = (int)Session[LocalizationAttribute.SESSION_LANGUAGE_ID];
             var userName   = User.Identity.Name;
             var user       = AclUserContext.GetDetail(dataContext, userName);
             if (user.AccountTypeEx != AccountTypeEnum.Admin)
             {
                 ContextUtils.CreateActionStateCookie(Response, ActionTypeEnum.Warning, GlobalRes.ERROR_NOT_ALLOWED);
                 return(RedirectToAction("Index", "Home"));
             }
             filter.PrepareFilter(languageId);
             int pageIndex     = page ?? 0;
             var itemList      = AclUserContext.GetList(dataContext, filter, pageIndex);
             var itemListModel = new AclUserListModel(itemList, pageIndex);
             var model         = new AclUserPageModel(itemListModel, filter);
             return(View(model));
         }
     }
     catch (Exception exception)
     {
         logger.Error(exception, "AdminController");
         return(RedirectToAction("Index", "Home"));
     }
 }
Beispiel #5
0
        public CheckInAnswerDetailModel(Question question, List <Answer> answerList, Language language)
        {
            this.Name         = question.Name;
            this.Description  = question.Description;
            this.QuestionType = question.QuestionTypeEx;
            var singleAnswer = answerList.FirstOrDefault(item => item.QuestionId == question.Id);

            if (this.QuestionType == QuestionTypeEnum.Checkbox)
            {
                this.BoolValue = (singleAnswer != null ? (singleAnswer.BoolValue ?? false) : false);
            }
            else if (this.QuestionType == QuestionTypeEnum.CheckboxList)
            {
                var optionList = question.Options.Where(item => item.IsDeleted == false).OrderBy(item => item.Order).ToList();
                this.CheckBoxList = optionList.ConvertAll(item => new CheckInCheckListDetailModel(item, answerList));
            }
            else if (this.QuestionType == QuestionTypeEnum.DropDown)
            {
                this.StringValue = (singleAnswer != null ? (singleAnswer.Option != null ? singleAnswer.Option.Name : null) : null);
            }
            else if (this.QuestionType == QuestionTypeEnum.Number)
            {
                this.StringValue = (singleAnswer != null ? ContextUtils.FormatFloat(singleAnswer.FloatValue, language) : null);
            }
            else if (this.QuestionType == QuestionTypeEnum.TextArea)
            {
                this.StringValue = (singleAnswer != null ? singleAnswer.StringValue.Replace(Environment.NewLine, "<br/>") : null);
            }
            else if (this.QuestionType == QuestionTypeEnum.TextBox)
            {
                this.StringValue = (singleAnswer != null ? singleAnswer.StringValue : null);
            }
        }
Beispiel #6
0
        private Group ProcessGroupObject(ISearchResultEntry entry,
                                         ResolvedSearchResult resolvedSearchResult)
        {
            var ret = new Group
            {
                ObjectIdentifier = resolvedSearchResult.ObjectId
            };

            ret.Properties.Add("domain", resolvedSearchResult.Domain);
            ret.Properties.Add("name", resolvedSearchResult.DisplayName);
            ret.Properties.Add("distinguishedname", entry.DistinguishedName.ToUpper());
            ret.Properties.Add("domainsid", resolvedSearchResult.DomainSid);

            if ((_methods & ResolvedCollectionMethod.ACL) != 0)
            {
                ret.Aces           = _aclProcessor.ProcessACL(resolvedSearchResult, entry).ToArray();
                ret.IsACLProtected = _aclProcessor.IsACLProtected(entry);
            }

            if ((_methods & ResolvedCollectionMethod.Group) != 0)
            {
                ret.Members = _groupProcessor
                              .ReadGroupMembers(resolvedSearchResult, entry)
                              .ToArray();
            }

            if ((_methods & ResolvedCollectionMethod.ObjectProps) != 0)
            {
                var groupProps = LDAPPropertyProcessor.ReadGroupProperties(entry);
                ret.Properties = ContextUtils.Merge(ret.Properties, groupProps);
            }

            return(ret);
        }
Beispiel #7
0
        private void ListMethods()
        {
            var inputBaseFolder = new Uri(Path.GetDirectoryName(IdlFilename) + "\\", UriKind.Absolute);
            var configBuilder   = CreateConfigBuilder(inputBaseFolder, Path.GetTempPath());
            var input           = new Uri(IdlFilename, UriKind.Absolute);

            try
            {
                _codeGenerator = new OCGenerator(configBuilder.Build());
                var contexts = _codeGenerator.GetContexts(input);
                var service  = ContextUtils.ExtractService(contexts[contexts.Count - 1]);
                if (service != null)
                {
                    m_PrunerPanel.Service = service;
                }
                else
                {
                    m_GenerateGroupBox.Enabled = false;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(this, "Code generation failed: " + ex.Message, Resources.ProductName,
                                MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Beispiel #8
0
 public ActionResult DemoLogin(string returnUrl)
 {
     try
     {
         using (var dataContext = new HuntingEntities())
         {
             UserSession userSession;
             var         demoUser = dataContext.AclUsers.FirstOrDefault(item => item.IsDeleted == false && item.AccountType == (int)AccountTypeEnum.Demo);
             var         result   = AclUserContext.LoginDemoUser(dataContext, demoUser, out userSession);
             if (result)
             {
                 FormsAuthentication.SetAuthCookie(userSession.AclUser.Email, false);
                 ContextUtils.CreateActionStateCookie(Response, ActionTypeEnum.Warning, AccountRes.SUCCESS_LOGIN_DEMO);
                 return(RedirectToLocal(returnUrl));
             }
             ContextUtils.CreateActionStateCookie(Response, ActionTypeEnum.Warning, AccountRes.ERROR_LOGIN_DEMO);
             return(RedirectToAction("Login", "Account"));
         }
     }
     catch (Exception exception)
     {
         logger.Error(exception, "AccountController");
         return(RedirectToAction("Index", "Home"));
     }
 }
 // GET: Territory/PersonList/id
 public ActionResult PersonList(int id)
 {
     try
     {
         using (var dataContext = new HuntingEntities())
         {
             var user = AclUserContext.GetDetail(dataContext, User.Identity.Name);
             if (user == null)
             {
                 ContextUtils.CreateActionStateCookie(Response, ActionTypeEnum.Warning, GlobalRes.ERROR_NOT_ALLOWED);
                 return(RedirectToAction("Index", "Home"));
             }
             var territory = TerritoryContext.GetDetail(dataContext, id);
             if (user.CanUpdateTerritory(territory) == false)
             {
                 ContextUtils.CreateActionStateCookie(Response, ActionTypeEnum.Warning, GlobalRes.ERROR_NOT_ALLOWED);
                 return(RedirectToAction("Index", "Territory", new { id = id }));
             }
             int languageId = (int)Session[LocalizationAttribute.SESSION_LANGUAGE_ID];
             var model      = new TerritoryPersonListModel(territory, languageId);
             return(View(model));
         }
     }
     catch (Exception exception)
     {
         logger.Error(exception, "TerritoryController");
         ContextUtils.CreateActionStateCookie(Response, ActionTypeEnum.Danger, GlobalRes.ERROR_EXCEPTION);
         return(RedirectToAction("Index", "Territory", new { id = id }));
     }
 }
Beispiel #10
0
 public CheckInListItemModel(CheckInListItem checkIn, Language language)
 {
     this.Id                = checkIn.Id;
     this.UserName          = checkIn.UserName;
     this.CheckTime         = ContextUtils.FormatDateTime(checkIn.CheckInTime, language);
     this.QuestionnaireName = checkIn.QuestionnaireName;
 }
 // GET: Territory/UpdateMap
 public ActionResult UpdateMap(int id)
 {
     try
     {
         using (var dataContext = new HuntingEntities())
         {
             var user = AclUserContext.GetDetail(dataContext, User.Identity.Name);
             if (user == null)
             {
                 ContextUtils.CreateActionStateCookie(Response, ActionTypeEnum.Warning, GlobalRes.ERROR_NOT_ALLOWED);
                 return(RedirectToAction("Index", "Home"));
             }
             var territory = TerritoryContext.GetDetail(dataContext, id);
             if (user.CanUpdateTerritory(territory) == false)
             {
                 ContextUtils.CreateActionStateCookie(Response, ActionTypeEnum.Warning, GlobalRes.ERROR_NOT_ALLOWED);
                 return(RedirectToAction("Index", "Home"));
             }
             var model = new TerritoryDetailModel(territory, user);
             return(View(model));
         }
     }
     catch (Exception exception)
     {
         logger.Error(exception, "TerritoryController");
         ContextUtils.CreateActionStateCookie(Response, ActionTypeEnum.Danger, GlobalRes.ERROR_EXCEPTION);
         return(RedirectToAction("Index", "Home"));
     }
 }
        public ActionResult SaveMapAjax(int id, string mapData)
        {
            var model = new TerritoryMapSavedModel();

            try
            {
                using (var dataContext = new HuntingEntities())
                {
                    var user = AclUserContext.GetDetail(dataContext, User.Identity.Name);
                    if (user == null)
                    {
                        ContextUtils.CreateActionStateCookie(Response, ActionTypeEnum.Warning, GlobalRes.ERROR_NOT_ALLOWED);
                        return(PartialView(model));
                    }
                    var territory = TerritoryContext.GetDetail(dataContext, id);
                    if (user.CanUpdateTerritory(territory) == false)
                    {
                        ContextUtils.CreateActionStateCookie(Response, ActionTypeEnum.Warning, GlobalRes.ERROR_NOT_ALLOWED);
                        return(PartialView(model));
                    }

                    var saveModel = JsonConvert.DeserializeObject <MapSaveDataModel>(mapData);
                    model = TerritoryContext.SaveMap(dataContext, id, saveModel, user.Id);
                    return(PartialView(model));
                }
            }
            catch (Exception exception)
            {
                logger.Error(exception, "TerritoryController");
                ContextUtils.CreateActionStateCookie(Response, ActionTypeEnum.Danger, GlobalRes.ERROR_EXCEPTION);
                return(PartialView(model));
            }
        }
Beispiel #13
0
        public ActionResult ChangePassword(ChangePasswordModel model)
        {
            try
            {
                using (var dataContext = new HuntingEntities())
                {
                    int languageId = (int)Session[LocalizationAttribute.SESSION_LANGUAGE_ID];
                    var aclUser    = AclUserContext.GetDetail(dataContext, User.Identity.Name);
                    if (aclUser == null)
                    {
                        ContextUtils.CreateActionStateCookie(Response, ActionTypeEnum.Warning, GlobalRes.ERROR_NOT_ALLOWED);
                        return(RedirectToAction("Index", "Home"));
                    }

                    if (ModelState.IsValid)
                    {
                        var isSuccess = AclUserContext.ChangePassword(dataContext, aclUser, model, false);
                        if (isSuccess)
                        {
                            FormsAuthentication.SetAuthCookie(aclUser.Email, false);
                            ContextUtils.CreateActionStateCookie(Response, ActionTypeEnum.Success, AccountRes.SUCCESS_PASSWORD_CHANGED);
                            return(RedirectToAction("Manage", "Account"));
                        }
                    }
                    model = new ChangePasswordModel(aclUser);
                    return(View(model));
                }
            }
            catch (Exception exception)
            {
                logger.Error(exception, "AccountController");
                ContextUtils.CreateActionStateCookie(Response, ActionTypeEnum.Danger, GlobalRes.ERROR_EXCEPTION);
                return(RedirectToAction("Index", "Home"));
            }
        }
Beispiel #14
0
        private async Task <IActionResult> _GetByFilterPaged(string filter = null, int?page = null, int?pageSize = null)
        {
            try
            {
                var ret     = (IEnumerable <Role>)null;
                var authRet = await ControllerUtils.AuthorizeUserAsync(HttpContext, _context, _testUserName, _adminRoleName, _defaultRoleName, _authorizedRolesAdmins);

                if (authRet.ErrorMessage != null)
                {
                    return(BadRequest(authRet.ErrorMessage));
                }
                filter = ContextUtils.ConvertFilterToLinq(filter);

                if (page.HasValue)
                {
                    ret = string.IsNullOrEmpty(filter)
                        ? _context.Roles.ToPagedList(page.Value, pageSize ?? _defaultPageSize)
                        : _context.Roles.FromSqlRaw($"SELECT * FROM dbo.Role WHERE ({filter})").ToPagedList(page.Value, pageSize ?? _defaultPageSize);
                }
                else
                {
                    ret = string.IsNullOrEmpty(filter)
                        ? await _context.Roles.ToListAsync()
                        : await _context.Roles.FromSqlRaw($"SELECT * FROM dbo.Role WHERE ({filter})").ToListAsync();
                }

                return(Ok(ret));
            }
            catch (SqlException e)
            {
                var columns = typeof(Role).GetProperties().Select(p => p.Name);
                return(BadRequest("\nGetByFilter(filter) - Sql Exception: " + e.Message + "\n\n" + "Columns: " + String.Join(", ", columns)));
            }
        }
Beispiel #15
0
        public ActionResult ChangePassword()
        {
            try
            {
                using (var dataContext = new HuntingEntities())
                {
                    int languageId = (int)Session[LocalizationAttribute.SESSION_LANGUAGE_ID];
                    var aclUser    = AclUserContext.GetDetail(dataContext, User.Identity.Name);
                    if (aclUser == null)
                    {
                        ContextUtils.CreateActionStateCookie(Response, ActionTypeEnum.Warning, GlobalRes.ERROR_NOT_ALLOWED);
                        return(RedirectToAction("Index", "Home"));
                    }

                    var model = new ChangePasswordModel(aclUser);
                    return(View(model));
                }
            }
            catch (Exception exception)
            {
                logger.Error(exception, "AccountController");
                ContextUtils.CreateActionStateCookie(Response, ActionTypeEnum.Danger, GlobalRes.ERROR_EXCEPTION);
                return(RedirectToAction("Index", "Home"));
            }
        }
Beispiel #16
0
 public UserLocationModel(UserLocation userLocation)
 {
     this.UserName  = userLocation.AclUser.Fullname;
     this.Created   = ContextUtils.DateTimeToUnixTime(userLocation.SysCreated);
     this.LocationX = userLocation.LocationX;
     this.LocationY = userLocation.LocationY;
 }
        public void TestAddDefaultDimensions(string jsonContextFile)
        {
            var context = ContextUtils.FromJsonFile(jsonContextFile);

            var dp = BuildDataPoint();

            dp.AddDefaultDimensions(context);

            var expectedDimensions = new Dictionary <string, string>
            {
                { "aws_execution_env", "" }, // Expected to be empty since the env var is not defined.
                { "aws_function_name", context.FunctionName },
                { "aws_function_version", context.FunctionVersion },
                { "aws_region", "us-west-2" },
                { "aws_account_id", "123456789012" },
                { "lambda_arn", $"{context.InvokedFunctionArn}:{context.FunctionVersion}" },
                { "function_wrapper_version", "signalfx_lambda_3.0.1.0" },
                { "metric_source", "lambda_wrapper" },
                { "test", "extensions" },
            };

            foreach (var dim in dp.dimensions)
            {
                Assert.Contains(dim.key, expectedDimensions.Keys);
                Assert.Equal(expectedDimensions[dim.key], dim.value);
            }
        }
Beispiel #18
0
        private GPO ProcessGPOObject(ISearchResultEntry entry,
                                     ResolvedSearchResult resolvedSearchResult)
        {
            var ret = new GPO
            {
                ObjectIdentifier = resolvedSearchResult.ObjectId
            };

            ret.Properties.Add("domain", resolvedSearchResult.Domain);
            ret.Properties.Add("name", resolvedSearchResult.DisplayName);
            ret.Properties.Add("distinguishedname", entry.DistinguishedName.ToUpper());
            ret.Properties.Add("domainsid", resolvedSearchResult.DomainSid);
            ret.Properties.Add("highvalue", false);

            if ((_methods & ResolvedCollectionMethod.ACL) != 0)
            {
                ret.Aces           = _aclProcessor.ProcessACL(resolvedSearchResult, entry).ToArray();
                ret.IsACLProtected = _aclProcessor.IsACLProtected(entry);
            }

            if ((_methods & ResolvedCollectionMethod.ObjectProps) != 0)
            {
                ret.Properties = ContextUtils.Merge(ret.Properties, LDAPPropertyProcessor.ReadGPOProperties(entry));
                if (_context.Flags.CollectAllProperties)
                {
                    ret.Properties = ContextUtils.Merge(_ldapPropertyProcessor.ParseAllProperties(entry),
                                                        ret.Properties);
                }
            }


            return(ret);
        }
Beispiel #19
0
        public static String descriptionToName(String value)
        {
            StringBuilder sb = new StringBuilder();

            for (int i = 0; i < value.Length; i++)
            {
                char c = value[i];
                sb.Append(ContextUtils.isValidContextNameChar(c) ? c : '_');
            }
            return(sb.ToString());
        }
Beispiel #20
0
        private static Boolean entityMatches(Permission has, Permission need)
        {
            if (has.getEntity() == null)
            {
                return(true);
            }

            return(need.getEntity() != null
                       ? ContextUtils.matchesToMask(has.getEntity(), need.getEntity(), true, false)
                       : false);
        }
Beispiel #21
0
        private async Task <User> ProcessUserObject(ISearchResultEntry entry,
                                                    ResolvedSearchResult resolvedSearchResult)
        {
            var ret = new User
            {
                ObjectIdentifier = resolvedSearchResult.ObjectId
            };

            ret.Properties.Add("domain", resolvedSearchResult.Domain);
            ret.Properties.Add("name", resolvedSearchResult.DisplayName);
            ret.Properties.Add("distinguishedname", entry.DistinguishedName.ToUpper());
            ret.Properties.Add("domainsid", resolvedSearchResult.DomainSid);

            if ((_methods & ResolvedCollectionMethod.ACL) != 0)
            {
                var aces = _aclProcessor.ProcessACL(resolvedSearchResult, entry);
                var gmsa = entry.GetByteProperty(LDAPProperties.GroupMSAMembership);
                ret.Aces           = aces.Concat(_aclProcessor.ProcessGMSAReaders(gmsa, resolvedSearchResult.Domain)).ToArray();
                ret.IsACLProtected = _aclProcessor.IsACLProtected(entry);
            }

            if ((_methods & ResolvedCollectionMethod.Group) != 0)
            {
                var pg = entry.GetProperty(LDAPProperties.PrimaryGroupID);
                ret.PrimaryGroupSID = GroupProcessor.GetPrimaryGroupInfo(pg, resolvedSearchResult.ObjectId);
            }

            if ((_methods & ResolvedCollectionMethod.ObjectProps) != 0)
            {
                var userProps = await _ldapPropertyProcessor.ReadUserProperties(entry);

                ret.Properties        = ContextUtils.Merge(ret.Properties, userProps.Props);
                ret.HasSIDHistory     = userProps.SidHistory;
                ret.AllowedToDelegate = userProps.AllowedToDelegate;
            }

            if ((_methods & ResolvedCollectionMethod.SPNTargets) != 0)
            {
                var spn = entry.GetArrayProperty(LDAPProperties.ServicePrincipalNames);

                var targets    = new List <SPNPrivilege>();
                var enumerator = _spnProcessor.ReadSPNTargets(spn, entry.DistinguishedName)
                                 .GetAsyncEnumerator(_cancellationToken);

                while (await enumerator.MoveNextAsync())
                {
                    targets.Add(enumerator.Current);
                }

                ret.SPNTargets = targets.ToArray();
            }

            return(ret);
        }
Beispiel #22
0
        public void TestFindInheritingTypes()
        {
            var types = ContextUtils.FindInheritingTypes(this.GetType().Assembly, new[] { typeof(InheritanceBase1) });

            Assert.AreEqual(4, types.Count());

            Assert.IsTrue(types.Contains(typeof(TypeB1)));
            Assert.IsTrue(types.Contains(typeof(TypeC1.TypeD)));
            Assert.IsTrue(types.Contains(typeof(TypeC1.TypeD.TypeE)));
            Assert.IsTrue(types.Contains(typeof(TypeF1.TypeI.TypeK)));
        }
Beispiel #23
0
        public static List <T> ReadPagedList <T>(DbContext context, IGenerator generator, int pageIndex, int pageSize = Constants.DEFAULT_LIST_PAGE_SIZE)
        {
            var queryParams = generator.QueryParams;
            var paging      = ContextUtils.GetPaging(pageIndex, pageSize, false);

            queryParams.Add(new SqlParameter("@SkipCount", paging.SkipCount));
            var query = GetFilterString(generator, paging.PageSize);
            var list  = (context as IObjectContextAdapter).ObjectContext.ExecuteStoreQuery <T>(query, queryParams.ToArray());

            return(list.ToList());
        }
Beispiel #24
0
        public RoleController(IConfiguration configuration, AppDbContext context, ILogger <RoleController> logger, string testUserName = null)
        {
            _configuration = configuration;
            _context       = context;
            _logger        = logger;
            _testUserName  = testUserName;

            _defaultRoleName       = _configuration.GetValue <string>("AppRoles:DefaultRole", Role.UserDefault);
            _adminRoleName         = _configuration.GetValue <string>("AppRoles:AdministratorRole", Role.AdministratorDefault);
            _defaultPageSize       = _configuration.GetValue <int>("RoleController:DefultPageSize", 5);
            _authorizedRolesAdmins = ContextUtils.RoleParameterToStringArray(_configuration.GetValue <string>("RoleController:AuthorisedRolesAdmins"));
        }
Beispiel #25
0
 public CheckInUpdateModel(Model.API.CreateCheckInModel checkIn, Questionnaire questionnaire)
 {
     this.IsCreate        = true;
     this.MapItemId       = checkIn.MapItemId;
     this.CheckDateTime   = ContextUtils.DateTimeFromUnixTime(checkIn.CheckTime);
     this.Note            = checkIn.Note;
     this.QuestionnaireId = checkIn.QuestionnaireId;
     if (checkIn.QuestionnaireId.HasValue)
     {
         this.QuestionList = checkIn.AnswerList.ConvertAll(item => new CheckInQuestionModel(item, questionnaire));
     }
 }
Beispiel #26
0
        public static List <EventDefinition> getEventDefinitions(ContextManager cm, String contextMask, String eventsMask, CallerController <CallerData> caller)
        {
            var events   = new List <EventDefinition>();
            var contexts = ContextUtils.expandContextMaskToContexts(contextMask, cm, caller);

            foreach (var context in contexts)
            {
                events.AddRange(getEvents(context, eventsMask, caller));
            }

            return(events);
        }
        //POST: Territory/Contact
        public ActionResult Contact(int id, string message)
        {
            try
            {
                using (var dataContext = new HuntingEntities())
                {
                    var user = AclUserContext.GetDetail(dataContext, User.Identity.Name);
                    if (user == null)
                    {
                        ContextUtils.CreateActionStateCookie(Response, ActionTypeEnum.Warning, GlobalRes.ERROR_NOT_ALLOWED);
                        return(RedirectToAction("Index", "Home"));
                    }
                    var territory = TerritoryContext.GetDetail(dataContext, id);
                    if (territory == null)
                    {
                        ContextUtils.CreateActionStateCookie(Response, ActionTypeEnum.Warning, GlobalRes.ERROR_NOT_FOUND);
                        return(RedirectToAction("List", "Territory"));
                    }
                    if (territory.StewardId == user.Id)
                    {
                        ContextUtils.CreateActionStateCookie(Response, ActionTypeEnum.Warning, GlobalRes.ERROR_NOT_ALLOWED);
                        return(RedirectToAction("List", "Territory"));
                    }
                    if (territory.TerritoryUsers.Any(item => item.AclUserId == user.Id))
                    {
                        ContextUtils.CreateActionStateCookie(Response, ActionTypeEnum.Warning, GlobalRes.ERROR_NOT_ALLOWED);
                        return(RedirectToAction("List", "Territory"));
                    }
                    if (territory.TerritoryUserContacts.Any(item => item.IsDeleted == false && item.AclUserId == user.Id))
                    {
                        ContextUtils.CreateActionStateCookie(Response, ActionTypeEnum.Warning, GlobalRes.ERROR_NOT_ALLOWED);
                        return(RedirectToAction("List", "Territory"));
                    }

                    var result = TerritoryContext.Contact(dataContext, territory, user, message);
                    if (result)
                    {
                        ContextUtils.CreateActionStateCookie(Response, ActionTypeEnum.Success, TerritoryRes.SUCCESS_CONTACT);
                    }
                    else
                    {
                        ContextUtils.CreateActionStateCookie(Response, ActionTypeEnum.Warning, TerritoryRes.ERROR_CONTACT);
                    }
                    return(RedirectToAction("List", "Territory"));
                }
            }
            catch (Exception exception)
            {
                logger.Error(exception, "TerritoryController");
                return(RedirectToAction("List", "Territory"));
            }
        }
Beispiel #28
0
        public ActionResult Update(UserPointUpdateModel model)
        {
            try
            {
                using (var dataContext = new HuntingEntities())
                {
                    int languageId = (int)Session[LocalizationAttribute.SESSION_LANGUAGE_ID];
                    var userName   = User.Identity.Name;

                    var user = AclUserContext.GetDetail(dataContext, userName);
                    if (user == null)
                    {
                        ContextUtils.CreateActionStateCookie(Response, ActionTypeEnum.Warning, GlobalRes.ERROR_NOT_ALLOWED);
                        return(RedirectToAction("Index", "Home"));
                    }

                    var userPoint = UserPointContext.GetUserPoint(dataContext, model.Id);
                    if (userPoint == null)
                    {
                        ContextUtils.CreateActionStateCookie(Response, ActionTypeEnum.Warning, GlobalRes.ERROR_NOT_FOUND);
                        return(RedirectToAction("Index", "Home"));
                    }
                    if (user.CanUpdateUserPoint(userPoint) == false)
                    {
                        ContextUtils.CreateActionStateCookie(Response, ActionTypeEnum.Warning, GlobalRes.ERROR_NOT_ALLOWED);
                        return(RedirectToAction("Index", "Home"));
                    }

                    model.Validate(ModelState);
                    if (ModelState.IsValid)
                    {
                        var itemId = UserPointContext.Update(dataContext, userPoint, model, user.Id);
                        if (itemId.HasValue)
                        {
                            ContextUtils.CreateActionStateCookie(Response, ActionTypeEnum.Success, UserPointRes.SUCCESS_UPDATE);
                            return(RedirectToAction("Index", "Territory", new { id = model.TerritoryId }));
                        }
                        ContextUtils.CreateActionStateCookie(Response, ActionTypeEnum.Warning, UserPointRes.ERROR_UPDATE);
                    }

                    model.FillTerritoryInfo(userPoint.Territory, user);
                    return(View(model));
                }
            }
            catch (Exception exception)
            {
                logger.Error(exception, "UserPointController");
                ContextUtils.CreateActionStateCookie(Response, ActionTypeEnum.Danger, GlobalRes.ERROR_EXCEPTION);
                return(RedirectToAction("Index", "Home"));
            }
        }
Beispiel #29
0
        public ActionResult Update(CheckInUpdateModel model)
        {
            try
            {
                using (var dataContext = new HuntingEntities())
                {
                    int languageId = (int)Session[LocalizationAttribute.SESSION_LANGUAGE_ID];
                    var language   = LanguageContext.GetLanguage(languageId);
                    var user       = AclUserContext.GetDetail(dataContext, User.Identity.Name);
                    if (user == null)
                    {
                        ContextUtils.CreateActionStateCookie(Response, ActionTypeEnum.Warning, GlobalRes.ERROR_NOT_ALLOWED);
                        return(RedirectToAction("Index", "Home"));
                    }
                    var checkIn = CheckInContext.GetDetail(dataContext, model.Id);
                    if (checkIn == null)
                    {
                        ContextUtils.CreateActionStateCookie(Response, ActionTypeEnum.Warning, GlobalRes.ERROR_NOT_FOUND);
                        return(RedirectToAction("Index", "Home"));
                    }
                    if (user.CanUpdateTerritory(checkIn.MapItem.Territory) == false)
                    {
                        ContextUtils.CreateActionStateCookie(Response, ActionTypeEnum.Warning, GlobalRes.ERROR_NOT_ALLOWED);
                        return(RedirectToAction("Index", "CheckIn", new { id = checkIn.MapItemId }));
                    }

                    CheckInContext.Validate(dataContext, model, ModelState);
                    if (ModelState.IsValid)
                    {
                        var newItemId = CheckInContext.Update(dataContext, checkIn, model, user, language);
                        if (newItemId.HasValue)
                        {
                            ContextUtils.CreateActionStateCookie(Response, ActionTypeEnum.Success, CheckInRes.SUCCESS_UPDATE);
                            return(RedirectToAction("Index", "CheckIn", new { id = model.MapItemId }));
                        }
                        else
                        {
                            ContextUtils.CreateActionStateCookie(Response, ActionTypeEnum.Warning, CheckInRes.ERROR_UPDATE);
                        }
                    }
                    model.FillCodeLists(dataContext, checkIn.MapItem);
                    return(View(model));
                }
            }
            catch (Exception exception)
            {
                logger.Error(exception, "CheckInController");
                ContextUtils.CreateActionStateCookie(Response, ActionTypeEnum.Danger, GlobalRes.ERROR_EXCEPTION);
                return(RedirectToAction("Index", "Home"));
            }
        }
Beispiel #30
0
        public CheckInUpdateModel(CheckIn checkIn, Language language)
        {
            this.Id        = checkIn.Id;
            this.MapItemId = checkIn.MapItemId;

            this.CheckTime       = ContextUtils.FormatDateTime(checkIn.CheckTime, language, true);
            this.Note            = checkIn.Note;
            this.QuestionnaireId = checkIn.QuestionnaireId;

            if (checkIn.QuestionnaireId.HasValue)
            {
                FillQuestionnaire(checkIn, checkIn.Questionnaire, language);
            }
        }