示例#1
0
        public ActionResult Edit(VMService model)
        {
            var isNew = model.Id == 0;

            if (isNew || (!isNew && model.TitleUrl == null))
            {
                model.TitleUrl = Url.SeoFriendlyUrl(model.Title);
            }

            if (ModelState.IsValid)
            {
                var redactModel = Mapper.Map <VMService, Service>(model);
                if (isNew)
                {
                    _repo.Create(redactModel);
                }
                else
                {
                    _repo.Update(redactModel);
                }

                return(RedirectToAction("Index"));
            }

            else
            {
                return(View(model));
            }
        }
示例#2
0
        public ActionResult Create(CompanyVM company)
        {
            //получение пользователя
            var user = new VMService(TMSService).GetUser((int)Session["Id"]);

            company.Creator = user;

            //создание компании в бд
            var mapperForCompany = new MapperConfiguration(cfg => cfg.CreateMap <CompanyVM, CompanyDTO>()).CreateMapper();
            var companyDTO       = mapperForCompany.Map <CompanyVM, CompanyDTO>(company);

            TMSService.MakeCompany(companyDTO);

            //получение списка компаний
            var companies = new VMService(TMSService).GetListCompaniesCreatedByUserID((int)Session["Id"]);

            //не ну мало ли
            int?companyId = null;

            if (companies.Count() == 1)
            {
                companyId = companies[0].Id;
            }
            else if (companies.Count() == 0)
            {
                throw new Exception("Не удалось создать компанию!");
            }

            return(RedirectToAction("Details", new { id = companyId }));
        }
示例#3
0
        public ActionResult Details(int id)
        {
            int?sessionId = GetSessionId();

            //получение компании
            var company = new VMService(TMSService).GetCompany(id);

            return(View(company));
        }
示例#4
0
        public ActionResult EditCompany(int id)
        {
            //авторизация
            int?sessionId = GetSessionId();

            //получение компании
            var company = new VMService(TMSService).GetCompany(id);

            //если есть компания то редактировать ее
            if (company.Creator.Id == sessionId)
            {
                return(View(company));
            }

            return(RedirectToAction("Index", "TMS"));
        }
示例#5
0
        //Создание компании
        public ActionResult Create()
        {
            int?sessionId = GetSessionId();
            //компании созданные пользователем
            var companies = new VMService(TMSService).GetCompaniesCreatedByUserID(sessionId);

            //если может создать то вьюшка создания
            bool canCreate = false;

            if (companies.Count() == 0)
            {
                canCreate = true;
            }

            ViewBag.canCreate = canCreate;
            return(View());
        }
示例#6
0
        public ActionResult Enter(bool?wrongPassOrSelfEntering)
        {
            int?sessionId = GetSessionId();

            //если вхождение в функцию было вызвано редиректом то нужно выдать соответсвующее сообщение
            if (wrongPassOrSelfEntering != null)
            {
                if ((bool)wrongPassOrSelfEntering)
                {
                    ViewBag.msg = "Неверный пароль вступлнения в компанию";
                }
                else
                {
                    ViewBag.msg = "Нельзя вступить в свою компанию";
                }
            }
            //получение списка компаний
            List <CompanyVM> Companies = new VMService(TMSService).GetListCompanies();
            //получение юзера
            var user = new VMService(TMSService).GetUser((int)Session["Id"]);

            //создание выпадающего списка компаний
            SelectList companiesSL = new SelectList(Companies, "Id", "Name");
            var        model       = new EnterCompanyVM {
                Companies = companiesSL
            };

            for (int i = 0; i < Companies.Count; i++)
            {
                bool employed = false;
                for (int j = 0; j < Companies[i].Users.Count; j++)
                {
                    if (Companies[i].Users[j].Id == user.Id)
                    {
                        employed = true;
                    }
                }
                if (employed)
                {
                    model.AlreadyEmployed = true;
                }
            }

            return(View(model));
        }
示例#7
0
        public async Task <ActionResult> Index(VMService filterModel, SxOrderItem order, int page = 1)
        {
            var filter = new SxFilter(page, _pageSize)
            {
                Order = order != null && order.Direction != SortDirection.Unknown ? order : null, WhereExpressionObject = filterModel
            };

            var viewModel = await _repo.ReadAsync(filter);

            if (page > 1 && !viewModel.Any())
            {
                return(new HttpNotFoundResult());
            }

            ViewBag.Filter = filter;

            return(PartialView("_GridView", viewModel));
        }
示例#8
0
        public ActionResult Update(int Id, string Commentary)
        {
            //получить ДТО и изменить в ней коментарий
            var SessionDTO = TMSService.GetSession(Id);

            SessionDTO.Commentary = Commentary;
            TMSService.UpdateSession(SessionDTO);

            //получить только что измененную сесиию
            var sessions = new VMService(TMSService).GetSession(Id);

            //доваить в нее доп инфу
            sessions.CompanyName = TMSService.GetCompany(sessions.CompanyId).Name;
            sessions.UserName    = TMSService.GetUser(sessions.UserId).Name;
            sessions.WorkTime    = sessions.EndTime - sessions.StartTime;

            return(PartialView("ListSessions", sessions));
        }
示例#9
0
        // GET: Session
        public ActionResult Index(int id, int?page)
        {
            //редирект или ид сессии
            int?sessionId = GetSessionId();

            //получение всех сессий
            var sessions = new VMService(TMSService).GetSessionsById(id);

            Session["companyId"] = sessions.ToList()[0].CompanyId;

            //дополнительная информация для VM
            foreach (var item in sessions)
            {
                item.CompanyName = TMSService.GetCompany(item.CompanyId).Name;
                item.UserName    = TMSService.GetUser(item.UserId).Name;
                item.WorkTime    = item.EndTime - item.StartTime;
            }

            int pageSize   = 3;
            int pageNumber = (page ?? 1);

            return(View(sessions.ToPagedList(pageNumber, pageSize)));
        }
示例#10
0
        // GET: TMS
        public ActionResult Index()
        {
            //получить ид сессии или редирект
            int?id = GetSessionId();

            if (id != null)
            {
                //получить пользователя
                var user = new VMService(TMSService).GetUser((int)id);

                //получить компании
                var companiesEmployee = new VMService(TMSService).GetListCompanies();

                CompanyVM        employedComp = null;
                List <CompanyVM> createdComp  = new List <CompanyVM>();

                //компании в которых сотрудник устроен
                for (int i = 0; i < companiesEmployee.Count; i++)
                {
                    bool employed = false;
                    for (int j = 0; j < companiesEmployee[i].Users.Count; j++)
                    {
                        if (companiesEmployee[i].Users[j].Id == user.Id)
                        {
                            employed = true;
                        }
                    }
                    if (employed)
                    {
                        employedComp = companiesEmployee[i];
                    }
                }

                //компании которые сотрудник создал
                for (int i = 0; i < companiesEmployee.Count; i++)
                {
                    bool created = false;
                    for (int j = 0; j < companiesEmployee[i].Users.Count; j++)
                    {
                        if (companiesEmployee[i].Creator.Id == user.Id)
                        {
                            created = true;
                        }
                    }
                    if (created)
                    {
                        CompanyVM company = new CompanyVM
                        {
                            Id      = companiesEmployee[i].Id,
                            Creator = companiesEmployee[i].Creator,
                            Name    = companiesEmployee[i].Name,
                            Users   = companiesEmployee[i].Users
                        };
                        createdComp.Add(company);
                    }
                }

                ViewBag.createdComp  = createdComp;
                ViewBag.employedComp = employedComp;
                return(View("Index", user));
            }
            return(RedirectToAction("Login", "Account"));
        }