Esempio n. 1
0
        public ActionResult Edit(int id)
        {
            ViewBag.branches = new SelectList(branchRepository.GetList(), "Id", "Name");
            DataAccessLayerCommon.ServicesHistory sh = serviceHistoryRepository.GetItem(id);


            ViewBag.serviceDirectories = new SelectList(servicesDirectoryRepository.GetAll(), "Id", "Name");

            Models.ServicesHistoryEdit servicesHistoryModel = serviceHistoryMapper.MapFromEntityEdit(serviceHistoryRepository.GetItem(id));
            Client c = clientRepository.GetItem(servicesHistoryModel.ClientId);

            servicesHistoryModel.FirstName  = c.FirstName;
            servicesHistoryModel.SecondName = c.SecondName;
            servicesHistoryModel.MiddleName = c.MiddleName;
            servicesHistoryModel.Id         = id;
            TempData["ClientId"]            = c.Id;

            ViewBag.BranchName = branchRepository.GetItem(servicesHistoryModel.BranchId).Name;
            Employee emp = employeeRepository.GetItem(servicesHistoryModel.EmployeeId);

            ViewBag.employees    = new SelectList(employeeRepository.GetList().Where(e => e.BranchId == emp.BranchId), "Id", "SecondName");
            ViewBag.EmployeeName = $"{emp.SecondName} {emp.FirstName[0]}. {emp.MiddleName[0]}.";
            ViewBag.ServiceName  = servicesDirectoryRepository.GetItem(servicesHistoryModel.ServicesDirectoryId).Name;
            return(View(servicesHistoryModel));
        }
 public ServicesHistoryEdit MapFromEntityEdit(DataAccessLayerCommon.ServicesHistory servicesHistory)
 {
     Models.ServicesHistoryEdit SHModel = new Models.ServicesHistoryEdit
     {
         ServicesDirectoryId = servicesHistory.ServicesDirectoryId,
         ClientId            = servicesHistory.ClientId,
         EmployeeId          = servicesHistory.EmployeeId,
         //Date = servicesHistory.Date,
         BranchId = employeeRepository.GetItemWithBranchAndPosition(servicesHistory.EmployeeId).BranchId
     };
     return(SHModel);
 }
        public DataAccessLayerCommon.ServicesHistory MapFromModelEdit(Models.ServicesHistoryEdit servicesHistory)
        {
            DataAccessLayerCommon.ServicesHistory sh = new DataAccessLayerCommon.ServicesHistory
            {
                ServicesDirectoryId = servicesHistory.ServicesDirectoryId,
                ClientId            = servicesHistory.ClientId,
                EmployeeId          = servicesHistory.EmployeeId,

                // Employee = employeeRepository.GetItemWithBranchAndPosition(servicesHistory.EmployeeId),
                // Client = clientRepository.GetItem(servicesHistory.ClientId),
                //ServicesDirectory = servicesDirectoryRepository.GetItem(servicesHistory.ServicesDirectoryId)
            };
            return(sh);
        }
Esempio n. 4
0
        public ActionResult Edit(Models.ServicesHistoryEdit servicesHistory, int id)
        {
            ViewBag.branches           = new SelectList(branchRepository.GetList(), "Id", "Name");
            ViewBag.employees          = new SelectList(employeeRepository.GetList(), "Id", "SecondName");
            ViewBag.serviceDirectories = new SelectList(servicesDirectoryRepository.GetAll(), "Id", "Name");
            servicesHistory.ClientId   = serviceHistoryRepository.GetItem(id).ClientId;
            servicesHistory.Id         = id;

            if (ModelState.IsValid)
            {
                DataAccessLayerCommon.ServicesHistory sh = serviceHistoryMapper.MapFromModelEdit(servicesHistory);
                sh.Date = DateTime.Now;
                servicesHistoryRepository.Update(id, sh);
                return(RedirectPermanent("/ServicesHistory/show/" + servicesHistory.ClientId));
            }
            return(View(servicesHistory));
        }
 public Models.ServicesHistoryShow MapFromEntityShow(DataAccessLayerCommon.ServicesHistory servicesHistory)
 {
     Models.ServicesHistoryShow SHModel = new Models.ServicesHistoryShow
     {
         Id       = servicesHistory.Id,
         Employee = new Models.Employee
         {
             FirstName  = servicesHistory.Employee.FirstName,
             SecondName = servicesHistory.Employee.SecondName,
             MiddleName = servicesHistory.Employee.MiddleName,
             Branch     = servicesHistory.Employee.Branch.Name,
             Id         = servicesHistory.Id,
             Position   = servicesHistory.Employee.Position.Name
         },
         Date = servicesHistory.Date,
         ServicesDirectoryName = servicesHistory.ServicesDirectory.Name,
     };
     return(SHModel);
 }
Esempio n. 6
0
        public ActionResult Add(int id, Models.ServicesHistoryEdit servicesHistory)
        {
            ViewBag.branches           = new SelectList(branchRepository.GetList(), "Id", "Name");
            ViewBag.employees          = new SelectList(employeeRepository.GetList(), "Id", "SecondName");
            ViewBag.serviceDirectories = new SelectList(servicesDirectoryRepository.GetAll(), "Id", "Name");

            Client client = clientRepository.GetItem(id);

            servicesHistory.FirstName  = client.FirstName;
            servicesHistory.SecondName = client.SecondName;
            servicesHistory.MiddleName = client.MiddleName;
            servicesHistory.ClientId   = client.Id;

            if (ModelState.IsValid)
            {
                DataAccessLayerCommon.ServicesHistory sh = serviceHistoryMapper.MapFromModelEdit(servicesHistory);
                sh.Date = DateTime.Now;
                servicesHistoryRepository.Insert(sh);
                return(RedirectPermanent("/ServicesHistory/show/" + id));
            }


            return(View(servicesHistory));
        }