示例#1
0
        public async Task <IActionResult> EditPosition(string id)
        {
            bool result = int.TryParse(id, out int appId);

            if (result)
            {
                var position = await context.Positions.Where(p => p.Id == Convert.ToInt32(id)).FirstOrDefaultAsync();

                if (position == null)
                {
                    Response.StatusCode = 404;
                    return(View("PositionNotFound", id));
                }
                else
                {
                    PositionViewModel model = new PositionViewModel()
                    {
                        Id   = position.Id,
                        Name = position.Name
                    };

                    if (model != null)
                    {
                        return(View(model));
                    }
                }
            }
            Response.StatusCode = 404;
            return(View("PositionNotFound", id));
        }
        private void dgEmployees_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            ShowCoffeeShopLocationEditor(false);

            EmployeeViewModel selected = dgEmployees.SelectedItem as EmployeeViewModel;

            if (selected != null)
            {
                _EmployeesPositions = new ObservableCollection <PositionViewModel>();
                _EmployeesPositions.CollectionChanged += _EmployeesPositions_CollectionChanged;

                var editableCollection = (IEditableCollectionView)dgPositions.Items;

                var positions = DbManager.GetInstance().GetPositionsOfEmployee(selected.Id);
                if (positions != null)
                {
                    foreach (var pos in positions)
                    {
                        PositionViewModel vm = PositionToViewModel(pos);
                        vm.EmployeeId = selected.Id;
                        _EmployeesPositions.Add(vm);
                    }
                }
                else
                {
                    _EmployeesPositions = new ObservableCollection <PositionViewModel>();
                }
                dgPositions.ItemsSource = _EmployeesPositions;
            }
        }
        public IActionResult AddPosition()
        {
            PositionViewModel positionViewModel = new PositionViewModel();

            positionViewModel.Departments = _dbContext.Departments.ToList();
            return(View(positionViewModel));
        }
示例#4
0
        /// <summary>
        /// Метод возвращает список всех сотрудников, находящихся на этой должности
        /// </summary>
        /// <param name="positionViewModel"></param>
        /// <param name="context"></param>
        /// <returns></returns>

        public static List <Employee> GetEmployees(this PositionViewModel positionViewModel, ApplicationDbContext context)
        {
            return(context.EmployeePositions
                   .Include(emp => emp.Employee)
                   .Where(posId => posId.PositionId == positionViewModel.Id).ToList()
                   .Select(emp => emp.Employee).ToList());
        }
        public ActionResult Index(PositionViewModel collection)
        {
            long totalCount;
            var  request = new FilteredModel <Position>
            {
                PageIndex = collection.ThisPageIndex,
                Order     = collection.PageOrder,
                OrderBy   = collection.PageOrderBy
            };
            var offset = (request.PageIndex - 1) * request.PageSize;
            var result = _mapper.Map <IList <PositionViewModel> >(_positionService.GetPaging(_mapper.Map <Position>(collection), out totalCount, request.OrderBy, request.Order, offset, request.PageSize));

            if (!result.Any() && totalCount > 0 && request.PageIndex > 1)
            {
                request.PageIndex = (int)(totalCount / request.PageSize);
                if (totalCount % request.PageSize > 0)
                {
                    request.PageIndex++;
                }
                result = _mapper.Map <IList <PositionViewModel> >(_positionService.GetPaging(_mapper.Map <Position>(collection), out totalCount, request.OrderBy, request.Order, offset, request.PageSize));
            }
            ViewBag.OnePageOfEntries = new StaticPagedList <PositionViewModel>(result, request.PageIndex, request.PageSize, (int)totalCount);
            ViewBag.SearchModel      = collection;
            return(View());
        }
 public ActionResult Delete(int id, PositionViewModel collection)
 {
     try
     {
         if (id > 0)
         {
             collection.UpdaterId = LogedInAdmin.Id;
             _positionService.Delete(_mapper.Map <Position>(collection));
             return(RedirectToAction("Index"));
         }
         ModelState.AddModelError(string.Empty, GeneralMessages.EmptyId);
         return(View(collection));
     }
     catch (Exception ex)
     {
         _logger.Error(ex);
         if (ex.InnerException != null && ex.InnerException.Source.Equals(GeneralMessages.ExceptionSource))
         {
             ModelState.AddModelError(string.Empty, ex.Message);
         }
         else
         {
             ModelState.AddModelError(string.Empty, GeneralMessages.UnexpectedError);
         }
         return(View(collection));
     }
 }
 public ActionResult Create(PositionViewModel collection, string selectedPositions)
 {
     try
     {
         if (ModelState.IsValid)
         {
             var model = _mapper.Map <Position>(collection);
             model.CreatorId = LogedInAdmin.Id;
             _positionService.Insert(model);
             return(RedirectToAction("Index"));
         }
         ModelState.AddModelError(string.Empty, GeneralMessages.DefectiveEntry);
         return(View(collection));
     }
     catch (Exception ex)
     {
         _logger.Error(ex);
         if (ex.Message.Contains("duplicate"))
         {
             ModelState.AddModelError(string.Empty, GeneralMessages.Duplicated);
         }
         else
         {
             if (ex.InnerException != null && ex.InnerException.Source.Equals(GeneralMessages.ExceptionSource))
             {
                 ModelState.AddModelError(string.Empty, ex.Message);
             }
             else
             {
                 ModelState.AddModelError(string.Empty, GeneralMessages.UnexpectedError);
             }
         }
         return(View(collection));
     }
 }
        private void btnDeletePosition_Click(object sender, RoutedEventArgs e)
        {
            PositionViewModel pos = dgPositions.SelectedItem as PositionViewModel;

            if (pos != null)
            {
                ShowCoffeeShopLocationEditor(false);
                if (DbManager.GetInstance().RemovePositionFromEmployee(ViewModelToPosition(pos), pos.EmployeeId))
                {
                    IList <EmployementPosition> empPosition = Employees.Where(emp => emp.Id == pos.EmployeeId).Single().Positions.ToList();
                    var theRemovedPosition = empPosition.Where(p => pos.Equals(p)).FirstOrDefault();
                    if (theRemovedPosition != null)
                    {
                        empPosition.Remove(theRemovedPosition);
                        Employees.Where(emp => emp.Id == pos.EmployeeId).Single().Positions = empPosition;
                    }
                    EmployeesPositions.Remove(pos);
                    dgPositions.ItemsSource = EmployeesPositions;
                }
                else
                {
                    MessageBox.Show("Deleting position was unsuccessful");
                }
            }
        }
示例#9
0
        public void UpdatePosition(PositionViewModel position)
        {
            using (IDbConnection dbConnection = Connection)
            {
                dbConnection.Open();
                var trans = dbConnection.BeginTransaction();

                try
                {
                    string sql = @"UPDATE Positions SET PositionName = @PositionName,
                                   LastModified = @LastModified, LastModifiedBy = @LastModifiedBy
                                   WHERE PositionId=@PositionId";

                    dbConnection.Execute(sql, position, trans);
                    trans.Commit();
                }
                catch (Exception ex)
                {
                    trans.Rollback();
                    throw new Exception("Something Wrong While Update Position", ex);
                }
                finally
                {
                    dbConnection.Close();
                }
            }
        }
示例#10
0
        public async Task Consume(ConsumeContext <TLGpsDataEvent> context)
        {
            if (SignalRHubManager.Clients == null)
            {
                return;
            }

            using (var dbContextScopeFactory = SignalRHubManager.DbContextScopeFactory.Create())
            {
                // get current gps device
                var box = await GetSenderBox(context.Message.Imei, dbContextScopeFactory);

                if (box != null)
                {
                    // set position
                    if (!SignalRHubManager.LastPosition.ContainsKey(box.Imei))
                    {
                        SignalRHubManager.LastPosition.Add(box.Imei, new GeofenceHelper.Position
                        {
                            Latitude  = context.Message.Lat,
                            Longitude = context.Message.Long
                        });
                    }
                    var position = new PositionViewModel(context.Message, box.Vehicle, SignalRHubManager.LastPosition[box.Imei]);
                    await SignalRHubManager.Clients.Group(position.CustomerName).receiveGpsStatements(position);

                    SignalRHubManager.LastPosition[box.Imei] = new GeofenceHelper.Position
                    {
                        Latitude  = context.Message.Lat,
                        Longitude = context.Message.Long
                    };
                }
            }
        }
示例#11
0
 public ResponseData AddByEntity(PositionViewModel data)
 {
     using (SATEntities db = new SATEntities())
     {
         ResponseData result = new Models.ResponseData();
         try
         {
             tb_Position model = new tb_Position();
             model.PoID       = data.PoID;
             model.PoCode     = data.PoCode;
             model.PoName     = data.PoName;
             model.PoStatus   = (data.Status == "1") ? true : false;
             model.TypeID     = data.TypeID;
             model.CreateBy   = UtilityService.User.UserID;
             model.CreateDate = DateTime.Now;
             model.ModifyBy   = UtilityService.User.UserID;
             model.ModifyDate = DateTime.Now;
             db.tb_Position.Add(model);
             db.SaveChanges();
         }
         catch (Exception)
         {
         }
         return(result);
     }
 }
        public PositionViewModel Add(PositionViewModel objVm)
        {
            var obj = Mapper.Map <PositionViewModel, Position>(objVm);

            _positionRepository.Insert(obj);
            return(objVm);
        }
示例#13
0
        public async Task Consume(ConsumeContext <TLGpsDataEvents> context)
        {
            if (SignalRHubManager.Clients == null)
            {
                return;
            }

            using (var dbContextScopeFactory = SignalRHubManager.DbContextScopeFactory.Create())
            {
                foreach (var @event in context.Message.Events)
                {
                    // get current gps device
                    var vehicleDto = await GetSenderBoxAsync(@event.Imei, dbContextScopeFactory).ConfigureAwait(false);

                    if (vehicleDto != null)
                    {
                        // set position
                        var lasPosition = await GetLastPositionAsync(vehicleDto.Id, dbContextScopeFactory).ConfigureAwait(false);

                        var position = new PositionViewModel(@event, vehicleDto, lasPosition);
                        if (string.IsNullOrEmpty(position.CustomerName))
                        {
                            return;
                        }
                        var reverseGeoCodingService = new ReverseGeoCodingService();
                        position.Address = await reverseGeoCodingService.ReverseGeocodeAsync(position.Latitude, position.Longitude).ConfigureAwait(false);

                        await SignalRHubManager.Clients.Group(position.CustomerName).receiveGpsStatements(position);
                    }
                }
            }
        }
示例#14
0
        public static PositionViewModel CreateAvailablePosition(this PositionRecord model)
        {
            var record = new PositionViewModel();

            record.InjectFrom(model);
            return(record);
        }
示例#15
0
        public static List <PositionViewModel> GetAll()
        {
            PositionViewModel        mappedPosition = new PositionViewModel();
            List <PositionViewModel> list           = new List <PositionViewModel>();


            List <PositionDto>  positions;
            HttpResponseMessage response = GlobalVariables.WebApiClient.GetAsync("Position").Result;

            positions = response.Content.ReadAsAsync <List <PositionDto> >().Result;

            foreach (var position in positions)
            {
                mappedPosition = Mapper.MapPosition(position);
                foreach (var staff in mappedPosition.Staff)
                {
                    var staffinjected = StaffLoader.GetInsertedById(staff.Id);
                    mappedPosition.Staff.Add(staffinjected);
                }
                list.Add(mappedPosition);
            }



            return(list);
        }
        private void GetPositionByName()
        {
            List <Performance.Error> errors        = new List <Performance.Error>();
            PositionViewModel        pvm           = null;
            List <Position>          authpositions = BllInstance.PositionBllInstance.GetPositionByLeaderID(_Operator.Id);

            try
            {
                Position p =
                    BllInstance.PositionBllInstance.GetPositionByName(_Context.Request.Params["Name"], _Operator);
                if (Position.FindPosition(authpositions, p.Id) == null)
                {
                    throw new Exception("你没有权限对 " + _Context.Request.Params["Name"] + " 申请职位变更。");
                }
                if (p != null)
                {
                    p = BllInstance.PositionBllInstance.GetPositionById(p.Id, _Operator);
                }
                pvm = new PositionViewModel(p);
            }
            catch (Exception e)
            {
                errors.Add(new Performance.Error("lblMessage", e.Message));
            }
            _ResponseString = string.Format("{{\"item\":{0},\"error\":{1}}}", JsonConvert.SerializeObject(pvm),
                                            JsonConvert.SerializeObject(errors));
        }
示例#17
0
        public ActionResult Edit(PositionViewModel model)
        {
            if (ModelState.IsValid)
            {
                if (Request["Submit"] == "Save")
                {
                    var Position = PositionRepository.GetPositionById(model.Id);
                    AutoMapper.Mapper.Map(model, Position);
                    Position.ModifiedUserId = WebSecurity.CurrentUserId;
                    Position.ModifiedDate   = DateTime.Now;
                    PositionRepository.UpdatePosition(Position);

                    TempData[Globals.SuccessMessageKey] = App_GlobalResources.Wording.UpdateSuccess;
                    return(RedirectToAction("Index"));
                }

                return(View(model));
            }

            return(View(model));

            //if (Request.UrlReferrer != null)
            //    return Redirect(Request.UrlReferrer.AbsoluteUri);
            //return RedirectToAction("Index");
        }
示例#18
0
        public async Task <JsonResult> AddPositionJSON(PositionViewModel position)
        {
            try
            {
                var positionDto = new PositionDTO
                {
                    Id          = position.Id,
                    Name        = position.Name,
                    MaxQuantity = position.MaxQuantity
                };

                if (position.Id > 0)
                {
                    await positionService.EditPositionTask(positionDto);
                }
                else
                {
                    await positionService.AddPositionTask(positionDto);
                }

                return(Json(new { success = true, data = position }, JsonRequestBehavior.AllowGet));
            }
            catch (ValidationException ex)
            {
                ModelState.AddModelError(ex.Property, ex.Message);
                return(Json(new { success = false, errorstring = ex.Message }, JsonRequestBehavior.AllowGet));
            }
        }
示例#19
0
        public async Task <List <PositionViewModel> > GetLastVehiclePositionAsync(string userName)
        {
            using (var contextFScope = _dbContextScopeFactory.Create())
            {
                _objectContext = contextFScope.DbContexts.Get <SmartFleetObjectContext>();
                var positions = new List <PositionViewModel>();

                var query = await(from customer in _objectContext.Customers
                                  join account in _objectContext.UserAccounts on customer.Id equals account.CustomerId
                                  where account.UserName == userName
                                  join vcl in _objectContext.Vehicles on customer.Id equals vcl.CustomerId into vehicleJoin
                                  from vehicle in vehicleJoin
                                  join box in _objectContext.Boxes on vehicle.Id equals box.VehicleId into boxesJoin
                                  from box in boxesJoin
                                  join position in _objectContext.Positions on box.Id equals position.Box_Id
                                  group position by position.Box_Id into g
                                  select new { boxId = g.Key, Position = g.OrderByDescending(x => x.Timestamp).Select(x => new PositionViewModel {
                        Address = x.Address, Latitude = x.Lat, Longitude = x.Long
                    }).FirstOrDefault() }).ToArrayAsync().ConfigureAwait(false);
                foreach (var item in query)
                {
                    var vehicle = await _objectContext.Boxes.Include(x => x.Vehicle).Where(x => x.Id == item.boxId).Select(x => new  { x.Vehicle.VehicleType, x.Vehicle.VehicleName, x.Vehicle.CustomerId, x.VehicleId }).FirstOrDefaultAsync().ConfigureAwait(false);

                    var pos = new PositionViewModel(vehicle?.VehicleName, vehicle?.CustomerId.ToString(), vehicle.VehicleType, vehicle?.VehicleId.ToString());
                    pos.Address   = item.Position.Address;
                    pos.Latitude  = item.Position.Latitude;
                    pos.Longitude = item.Position.Longitude;
                    positions.Add(pos);
                }
                return(positions);
            }
        }
        public async Task <IActionResult> Create(PositionViewModel model)
        {
            if (ModelState.IsValid)
            {
                int TableOrganizations = _context.TableOrganizations.Include(i => i.users).FirstOrDefault
                                             (i => User.Identity.Name == i.users.UserName).TableOrganizationsId;

                TablePosition position = new TablePosition
                {
                    DateOfJobRegistration = DateTime.Now,
                    CountPosition         = model.CountPosition,
                    JobResponsibilities   = model.JobResponsibilities,
                    PositionId            = model.PositionId,
                    TableOrganizationsId  = TableOrganizations,
                };

                _context.TablePosition.Add(position);
                await _context.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }
            else
            {
                var positions = await _context.Position.ToListAsync();

                model.positions = positions;
                return(View(model));
            }
        }
示例#21
0
        public async Task <IActionResult> SetPosition([FromBody] PositionViewModel model)
        {
            try
            {
                if (string.IsNullOrWhiteSpace(model.Description))
                {
                    return
                        (BadRequest("Debe indicar el nombre de la posición"));
                }


                var item = new Position
                {
                    Description = model.Description
                };

                var result = await _Service.Save(item);

                return
                    (Ok(result));
            }
            catch (Exception ex)
            {
                return(BadRequest(ex.Message));
            }
        }
示例#22
0
 public ActionResult Position(PositionViewModel model)
 {
     if (!ModelState.IsValid)
     {
         return(View(model));
     }
     try
     {
         var position = new Position
         {
             PositionName        = model.Name,
             PositionDescription = model.Description
         };
         if (_societyRepository.AddPosition(position))
         {
             var returnData = new ReturnData
             {
                 HasValue = true,
                 Message  = "Position was successfully created"
             };
             TempData["returnMessage"] = returnData;
             return(Redirect("Position"));
         }
         ModelState.AddModelError(string.Empty, "There was an error completing the request, Please try again");
         return(View(model));
     }
     catch (Exception e)
     {
         //error occured
         ModelState.AddModelError(string.Empty, "There was an error completing the request, Please try again later");
         ErrorUtil.LogError(e);
         return(View(model));
     }
 }
示例#23
0
        public async Task UpdatePosition(PositionViewModel viewModel)
        {
            var position = _mapper.Map <Position>(viewModel);

            _context.Update(position);
            await _context.SaveChangesAsync();
        }
示例#24
0
        public FrameworkElement GetPropertyPage(EPropPage pg, string connection, string lang)
        {
            switch (pg)
            {
            case EPropPage.pDokument:
                var vmDoc = new DocumentViewModel();
                Nacist(vmDoc);
                vmDoc.Broker = s_broker;
                var docView = new DocumentView {
                    DataContext = vmDoc
                };
#if (DEBUG)
                return(new Okna.Plugins.Interception.InterceptionView(docView, true));
#else
                return(docView);
#endif

            case EPropPage.pDziura:
                var vmPos = new PositionViewModel();
                Nacist(vmPos);
                s_broker.Position = vmPos;
                var posView = new PositionView {
                    DataContext = vmPos
                };
#if (DEBUG)
                return(new Okna.Plugins.Interception.InterceptionView3(posView));
#else
                return(posView);
#endif
            }

            return(null);
        }
示例#25
0
        private IEnumerable <MediaListModel> LoadPositionMedia(PositionViewModel position)

        {
            List <MediaListModel> list = new List <MediaListModel>();

            try

            {
                string positionFileName = GetPositionFileName(position);

                XmlSerializer serializer = new XmlSerializer(typeof(List <MediaListModel>));

                StreamReader textReader = File.OpenText(positionFileName);

                list = serializer.Deserialize(textReader) as List <MediaListModel>;

                textReader.Close();
            }

            catch (Exception)

            {
                list = new List <MediaListModel>();
            }

            return(list);
        }
示例#26
0
        public ActionResult Add(int firmId, int?supPosId)
        {
            PositionViewModel pvm = new PositionViewModel();

            loadLookUp(pvm, firmId);
            pvm.ParentId = supPosId;
            return(View(pvm));
        }
        public static PositionViewModel ToViewModel(Position position)
        {
            var ViewModel = new PositionViewModel();

            ViewModel.Id   = position.PositionId;
            ViewModel.Name = position.PositionName;
            return(ViewModel);
        }
示例#28
0
        private PositionViewModel GetTarget()
        {
            PositionViewModel target = new PositionViewModel();

            target.OknaDocument = _oknaDoc;
            ExtensionsFactory.Nacist(target);
            return(target);
        }
示例#29
0
 public void Delete(PositionViewModel positionViewModel)
 {
     Model.Positions.Remove(positionViewModel.Model);
     m_Positions.Remove(positionViewModel);
     CloseEditor();
     NotifyOfPropertyChange(() => FilteredPositions);
     Save();
 }
示例#30
0
        public PositionViewModel Save(PositionViewModel position)
        {
            var pos = fromPos(position);

            db.Entry(pos).State = EntityState.Modified;
            db.SaveChanges();
            return(PosDto(pos));
        }
        public ActionResult Position(GridOptionsModel options)
        {
            if(!options.id.HasValue)
            {
                DisplayError("No position specified.");
                return View(new PositionViewModel {Data = new List<UserPositionModel>().AsPagination(options.Page, 10), Position = new PositionModel()});
            }

            var searchCriteria = new UserPositionsSearchCriteria
                                     {
                                         Ascending = options.Ascending,
                                         DistinctRootEntity = true,
                                         OrderByProperty = options.Column,
                                         Positions = new[] {options.id.Value}
                                     };
            var userPositions = _positionService.FindUserPositions(searchCriteria);
            var model = new PositionViewModel
                            {
                                Position = Mapper.Map<Position, PositionModel>(!userPositions.Any()
                                                                            ? _positionService.GetPosition(options.id.Value)
                                                                            : userPositions.First().Position),
                                Data = Mapper.Map<IEnumerable<UserPosition>, IEnumerable<UserPositionModel>>(userPositions).AsPagination(options.Page, 10)
                            };

            return View(model);
        }