public async Task <IActionResult> PutPositionLevel(int id, PositionLevel positionLevel)
        {
            if (id != positionLevel.Id)
            {
                return(BadRequest());
            }

            _context.Entry(positionLevel).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!PositionLevelExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
Пример #2
0
        public JsonResult EditPositionGroupConfirmed(List <int> lstPosition, int groupid)
        {
            var group = context.Groups.Find(groupid);

            context.Groups.Attach(group);
            context.Entry(group).Collection(g => g.PositionLevels).Load();
            var lstPositionLevelView = new List <PositionLevelView>();

            if (lstPosition != null)
            {
                foreach (int position in lstPosition)
                {
                    if (group.PositionLevels.FirstOrDefault(g => g.Id == position) == null)
                    {
                        PositionLevel p = context.PositionLevels.Find(position);
                        lstPositionLevelView.Add(new PositionLevelView()
                        {
                            Id = p.Id, Name = p.Name
                        });
                        group.PositionLevels.Add(p);
                    }
                }
            }
            context.SaveChanges();
            ViewBag.groupid = groupid;
            string strViewPosition = "";// this.RenderRazorViewToString("/Views/Employee/PositionView.cshtml", lstPositionLevelView);

            return(Json(new { viewposition = strViewPosition }));
        }
        public async Task <ActionResult <PositionLevel> > PostPositionLevel(PositionLevel positionLevel)
        {
            _context.PositionLevels.Add(positionLevel);
            await _context.SaveChangesAsync();

            return(CreatedAtAction("GetPositionLevel", new { id = positionLevel.Id }, positionLevel));
        }
Пример #4
0
        public static Position Create(Organization organization, PositionLevel level, Person createdByPerson, Position createdByPosition, PositionType positionType,
                                      PositionTitle positionTitle, bool volunteerable, bool overridable, Position reportsTo, Position dotReportsTo,
                                      int minCount, int maxCount)
        {
            if (level == PositionLevel.Geography)
            {
                throw new ArgumentException(
                          "Cannot use the geographyless creator to create geography-specific positions.");
            }

            if (organization == null && level != PositionLevel.SystemWide)
            {
                throw new ArgumentException("Cannot use null organization with any other level than PositionLevel.SystemWide");
            }

            int positionId = SwarmDb.GetDatabaseForWriting()
                             .CreatePosition(
                level, organization == null? 0 : organization.Identity, 0 /* geographyId */, 0 /*overridesHigherId */,
                createdByPerson == null ? 0 : createdByPerson.Identity, createdByPosition == null ? 0 : createdByPosition.Identity,
                positionType.ToString(), positionTitle.ToString(),
                false /*inheritsDownward*/, volunteerable, overridable,
                reportsTo == null ? 0 : reportsTo.Identity,
                dotReportsTo == null ? 0 : dotReportsTo.Identity,
                minCount, maxCount);

            return(FromIdentityAggressive(positionId));
        }
Пример #5
0
        private static BasicPosition ReadPositionFromDataReader(IDataRecord reader)
        {
            // groups of five to match the field sequence string lines (maintainability)

            int           positionId                = reader.GetInt32(0);
            PositionLevel positionLevel             = (PositionLevel)reader.GetInt32(1);
            int           organizationId            = reader.GetInt32(2);
            int           geographyId               = reader.GetInt32(3);
            int           overridesHigherPositionId = reader.GetInt32(4);

            int      createdByPersonId   = reader.GetInt32(5);
            int      createdByPositionId = reader.GetInt32(6);
            DateTime createdDateTimeUtc  = reader.GetDateTime(7);
            string   positionTypeName    = reader.GetString(8);
            string   positionTitleName   = reader.GetString(9);

            bool inheritsDownward = reader.GetBoolean(10);
            bool active           = reader.GetBoolean(11);
            bool volunteerable    = reader.GetBoolean(12);
            bool overridable      = reader.GetBoolean(13);
            bool covert           = reader.GetBoolean(14);

            int reportsToPositionId    = reader.GetInt32(15);
            int dotReportsToPositionId = reader.GetInt32(16);
            int minCount = reader.GetInt32(17);
            int maxCount = reader.GetInt32(18);

            return(new BasicPosition(
                       positionId, positionLevel, organizationId, geographyId, overridesHigherPositionId,
                       createdByPersonId, createdByPositionId, createdDateTimeUtc, positionTypeName, positionTitleName,
                       inheritsDownward, active, volunteerable, overridable, covert,
                       reportsToPositionId, dotReportsToPositionId, minCount, maxCount));
        }
Пример #6
0
    public void Move(PositionLevel posLvl)
    {
        if (restartBtn.activeInHierarchy == false)
        {
            heroPosLevel = posLvl;
            float transformX = 0.73F, transformY = 1.18F;

            if (heroPosLevel == PositionLevel.LeftUp || heroPosLevel == PositionLevel.RigthUp)
            {
                chair.transform.position = new Vector3(chairX, -2.72F, 0);
            }
            else if (heroPosLevel == PositionLevel.LeftDown || heroPosLevel == PositionLevel.RightDown)
            {
                transformY = 0;
                chair.transform.position = new Vector3(chairX, -10F, 0);
            }
            if (heroPosLevel == PositionLevel.RightDown || heroPosLevel == PositionLevel.RigthUp)
            {
                isFacingRight = true;
                Flip(maskot);
            }
            else if (heroPosLevel == PositionLevel.LeftUp || heroPosLevel == PositionLevel.LeftDown)
            {
                isFacingRight = false;
                transformX   *= -1;
                Flip(maskot);
            }
            maskot.transform.position = new Vector3(centerX + transformX, centerY + transformY, maskot.transform.position.z);
        }
    }
Пример #7
0
        public BasicPosition(
            int positionId, PositionLevel positionLevel, int organizationId, int geographyId, int overridesHigherPositionId,
            int createdByPersonId, int createdByPositionId, DateTime createdDateTimeUtc, string positionTypeName, string positionTitleName,
            bool inheritsDownward, bool active, bool volunteerable, bool overridable, bool covert,
            int reportsToPositionId, int dotReportsToPositionId, int minCount, int maxCount)
        {
            // Mind the order, for maintainability and risk reduction. Same order everywhere -
            // here and in database and in Swarmops.Database, in groups of five.

            this.PositionId                = positionId;
            this.PositionLevel             = positionLevel;
            this.OrganizationId            = organizationId;
            this.GeographyId               = geographyId;
            this.OverridesHigherPositionId = overridesHigherPositionId;

            this.CreatedByPersonId   = createdByPersonId;
            this.CreatedByPositionId = createdByPositionId;
            this.CreatedDateTimeUtc  = createdDateTimeUtc;
            this.PositionTypeName    = positionTypeName;
            this.PositionTitleName   = positionTitleName;

            this.InheritsDownward = inheritsDownward;
            this.Active           = active;
            this.Volunteerable    = volunteerable;
            this.Overridable      = overridable;
            this.Covert           = covert;

            this.ReportsToPositionId    = reportsToPositionId;
            this.DotReportsToPositionId = dotReportsToPositionId;
            this.MinCount = minCount;
            this.MaxCount = maxCount;
        }
 private void ValidatePositionLevelModel(PositionLevel level)
 {
     if (_positionLevelService.IsNameDuplicated(level.Company_Id, level.Name))
     {
         ModelState.AddModelError(ViewRes.Controllers.Shared.Name, ViewRes.Controllers.Shared.NameText);
     }
     if (_positionLevelService.IsLevelDuplicated(level.Company_Id, level.Level))
     {
         ModelState.AddModelError(ViewRes.Controllers.Shared.Level, ViewRes.Controllers.Shared.LevelText);
     }
 }
Пример #9
0
 public void InsertOrUpdate(PositionLevel PositionLevel)
 {
     if (PositionLevel.Id == default(int))
     {
         // New entity
         _context.PositionLevels.Add(PositionLevel);
     }
     else
     {
         // Existing entity
         _context.Entry(PositionLevel).State = EntityState.Modified;
     }
 }
 public ActionResult Create(PositionLevel level)
 {
     level.Company_Id = (int)new UsersServices().GetByUserName(User.Identity.Name.ToString()).Company_Id;
     ValidatePositionLevelModel(level);
     if (ModelState.IsValid)
     {
         if (_positionLevelService.Add(level))
         {
             return(RedirectToAction("Index"));
         }
     }
     InitializeViews(null);
     return(View(_positionLevelViewModel));
 }
 public IActionResult Save(PositionLevelIndexViewModel model)
 {
     if (ModelState.IsValid)
     {
         var userId = int.Parse(HttpContext.Session.GetString("UserId"));
         var item   = new PositionLevel
         {
             Id          = model.Item.Id,
             Description = model.Item.Description,
             Level       = model.Item.Level,
         };
         _Services.Save(item, userId);
     }
     return(RedirectToAction("Index"));
 }
Пример #12
0
        public static Position Create(PositionLevel level, Person createdByPerson, Position createdByPosition, PositionType positionType,
                                      PositionTitle positionTitle, bool volunteerable, bool overridable, Position reportsTo, Position dotReportsTo,
                                      int minCount, int maxCount)
        {
            if (level != PositionLevel.SystemWide)
            {
                throw new ArgumentException(
                          "Can only create system-wide positions (e.g. sysadmin) with this organizationless Position.Create() version.");
            }

            // Use more general Create() do to the actual work

            return(Create(null, level, createdByPerson, createdByPosition, positionType, positionTitle, volunteerable,
                          overridable, reportsTo, dotReportsTo, minCount, maxCount));
        }
        private void InitializeViews(int?level_id)
        {
            PositionLevel level;
            User          user = new UsersServices().GetByUserName(User.Identity.Name.ToString());

            if (level_id != null)
            {
                level = _positionLevelService.GetById((int)level_id);
            }
            else
            {
                level = new PositionLevel();
            }
            _positionLevelViewModel = new PositionLevelViewModel(level);
        }
Пример #14
0
        private void CreatePositionLevels()
        {
            PositionLevelsServices pls = new PositionLevelsServices();

            foreach (PositionLevel level in pls.GetByCompany(1117))
            {
                PositionLevel newLevel = new PositionLevel();
                newLevel.Company_Id = Company.Id;
                newLevel.Level      = level.Level;
                newLevel.Name       = level.Name;
                newLevel.ShortName  = level.ShortName;
                if (!pls.Add(newLevel))
                {
                    this.Ok = false;
                }
            }
        }
        public IActionResult PutPositionLevel(int id, PositionLevel positionLevel)
        {
            if (id != positionLevel.Id)
            {
                return(BadRequest());
            }

            try
            {
                _positionsLevelService.UpdatePositionsLevel(id, positionLevel);
            }
            catch (DbUpdateConcurrencyException ex)
            {
                string msg = ex.Message;
            }

            return(NoContent());
        }
Пример #16
0
 public void Save(PositionLevel item, int userId)
 {
     if (item.Id == 0)
     {
         item.CreatedBy    = userId.ToString();
         item.CreationDate = DateTime.Now;
         _dbContext.Add(item);
     }
     else
     {
         var entry = _dbContext.PositionLevels.FirstOrDefault(a => a.Id == item.Id);
         entry.Description             = item.Description;
         entry.Level                   = item.Level;
         item.ModifiedBy               = userId.ToString();
         item.ModifiedDate             = DateTime.Now;
         _dbContext.Entry(entry).State = EntityState.Modified;
     }
     _dbContext.SaveChanges();
 }
Пример #17
0
        public int CreatePosition(
            PositionLevel positionLevel, int organizationId, int geographyId, int overridesHigherPositionId,
            int createdByPersonId, int createdByPositionId, /* DateTimeCreatedUtc is measured below, */ string positionTypeName, string positionTitleName,
            bool inheritsDownward, /* active defaults true, */ bool volunteerable, bool overridable, /* covert defaults false, */
            int reportsToPositionId, int dotReportsToPositionId, int minCount, int maxCount)
        {
            DateTime utcNow = DateTime.UtcNow;

            using (DbConnection connection = GetMySqlDbConnection())
            {
                connection.Open();

                DbCommand command = GetDbCommand("CreatePosition", connection);
                command.CommandType = CommandType.StoredProcedure;

                AddParameterWithName(command, "positionLevel", (int)positionLevel);
                AddParameterWithName(command, "organizationId", organizationId);
                AddParameterWithName(command, "geographyId", geographyId);
                AddParameterWithName(command, "overridesHigherPositionId", overridesHigherPositionId);

                AddParameterWithName(command, "createdByPersonId", createdByPersonId);
                AddParameterWithName(command, "createdByPositionId", createdByPositionId);
                AddParameterWithName(command, "createdDateTimeUtc", utcNow);
                AddParameterWithName(command, "positionType", positionTypeName);
                AddParameterWithName(command, "positionTitle", positionTitleName);

                AddParameterWithName(command, "inheritsDownward", volunteerable);
                // active defaults to true
                AddParameterWithName(command, "volunteerable", volunteerable);
                AddParameterWithName(command, "overridable", volunteerable);
                // covert defaults to false

                AddParameterWithName(command, "reportsToPositionId", reportsToPositionId);
                AddParameterWithName(command, "dotReportsToPositionId", dotReportsToPositionId);
                AddParameterWithName(command, "minCount", minCount);
                AddParameterWithName(command, "maxCount", maxCount);

                return(Convert.ToInt32(command.ExecuteScalar()));
            }
        }
 public ActionResult Edit(int id, FormCollection collection)
 {
     if (GetAuthorization(_positionLevelService.GetById(id)))
     {
         try
         {
             PositionLevel positionLevel = _positionLevelService.GetById(id);
             UpdateModel(positionLevel, "Level");
             _positionLevelService.SaveChanges();
             return(RedirectToAction("Index"));
         }
         catch
         {
             InitializeViews(id);
             return(View(_positionLevelViewModel));
         }
     }
     else
     {
         return(RedirectToLogOn());
     }
 }
 public void Add(PositionLevel positionLevel)
 {
     try
     {
         if (positionLevel != null)
         {
             _context.Add(positionLevel);
             _context.SaveChanges();
         }
         else
         {
             var response = new HttpResponseMessage(HttpStatusCode.NotFound)
             {
                 Content    = new StringContent("Position Level doesn't exist", System.Text.Encoding.UTF8, "text/plain"),
                 StatusCode = HttpStatusCode.NotFound
             };
             throw new HttpResponseException(response);
         }
     }
     catch (Exception ex)
     {
         msg = ex.Message;
     };
 }
Пример #20
0
        protected void Page_Load(object sender, EventArgs e)
        {
            Response.ContentType = "application/json";

            // If level if system-wide, execute this block. Also, move the data to the real place, please

            JsonPositions rootPositions = new JsonPositions();

            _customCookieClass = "LocalPosition" + Request["Cookie"];                                 // may be null and that's ok

            PositionLevel level = (PositionLevel)Enum.Parse(typeof(PositionLevel), Request["Level"]); // may throw on invalid param but so what, that's what should happen anyway

            if (level == PositionLevel.SystemWide)
            {
                Tree <Position> systemPositions = Positions.ForSystem().Tree;

                if (CurrentAuthority.HasSystemAccess())
                {
                    _assignable = true;
                }

                Response.Output.WriteLine(RecursePositionTree(systemPositions.RootNodes));
                Response.End();
                return;
            }

            else if (level == PositionLevel.OrganizationStrategic)
            {
                // If this level does not exist yet for this org, create a starting point

                Positions orgStrategicPositions =
                    Positions.ForOrganization(CurrentOrganization).AtLevel(PositionLevel.OrganizationStrategic);

                if (orgStrategicPositions.Count == 0)
                {
                    throw new InvalidOperationException("Positions are not initialized or are missing.");
                }

                if (CurrentAuthority.HasAccess(new Access(CurrentOrganization, AccessAspect.Administration)))
                {
                    _assignable = true;
                }

                Response.Output.WriteLine(RecursePositionTree(orgStrategicPositions.Tree.RootNodes));
            }

            else if (level == PositionLevel.OrganizationExecutive)
            {
                Positions orgExecutivePositions =
                    Positions.ForOrganization(CurrentOrganization).AtLevel(PositionLevel.OrganizationExecutive);

                if (orgExecutivePositions.Count == 0)
                {
                    throw new InvalidOperationException("Positions are not initialized or are missing.");
                }

                if (CurrentAuthority.HasAccess(new Access(CurrentOrganization, AccessAspect.Administration)) ||
                    CurrentAuthority.HasAccess(new Access(CurrentOrganization, Geography.Root, AccessAspect.Administration)))
                {
                    _assignable = true;
                }

                Response.Output.WriteLine(RecursePositionTree(orgExecutivePositions.Tree.RootNodes));
            }

            else if (level == PositionLevel.GeographyDefault)
            {
                Positions positions =
                    Positions.ForOrganization(CurrentOrganization).AtLevel(PositionLevel.GeographyDefault);

                if (positions.Count == 0)
                {
                    throw new InvalidOperationException("Positions are not initialized or are missing.");
                }
                _displayAssignments = false;                                              // Suppresses assignment lookup, which would fail for default positions

                Response.Output.WriteLine(RecursePositionTree(positions.Tree.RootNodes)); // TODO: turn off assignability!
            }

            else if (level == PositionLevel.Geography)
            {
                _geographyId = Convert.ToInt32(Request["GeographyId"]);
                Geography geography = Geography.FromIdentity(_geographyId);

                if (CurrentAuthority.HasAccess(new Access(CurrentOrganization, AccessAspect.Administration)))
                {
                    _assignable = true;
                }

                Tree <Position> positions = Positions.ForOrganizationGeography(CurrentOrganization, geography);
                Response.Output.WriteLine(RecursePositionTree(positions.RootNodes));
            }
        }
 public ActionResult <PositionLevel> PostPositionLevel(PositionLevel positionLevel)
 {
     _positionsLevelService.AddPositionsLevel(positionLevel);
     return(CreatedAtAction("GetPositionLevel", new { id = positionLevel.Id }, positionLevel));
 }
 private bool GetAuthorization(PositionLevel level)
 {
     return(new SharedAdminAuthorization(new UsersServices().GetByUserName(User.Identity.Name),
                                         new CompaniesServices().GetById(level.Company_Id)).isAuthorizated());
 }
Пример #23
0
 public PositionLevelViewModel(PositionLevel level)
 {
     this.level = level;
 }
Пример #24
0
 public Positions AtLevel(PositionLevel level)
 {
     return(FromArray(this.Where(position => position.PositionLevel == level).ToArray()));
 }
Пример #25
0
 public void UpdatePositionsLevel(int PositionsLevelId, PositionLevel positionLevel)
 {
     _unitOfWork.positionLevels.Update(PositionsLevelId, positionLevel);
 }
Пример #26
0
 public void AddPositionsLevel(PositionLevel PositionsLevel)
 {
     _unitOfWork.positionLevels.Add(PositionsLevel);
 }