Пример #1
0
        public ActionResult Edit(DeviceUserDto model)
        {
            ResultHelper result = JsonConvert.DeserializeObject <ResultHelper>(deviceUserService.SetDeviceUser(model));

            ViewBag.Message = Helper.GetResultMessage(result.Result, result.ResultDescription);
            return(View());
        }
Пример #2
0
 public ResultHelper SetDeviceUser(DeviceUserDto deviceUserDto)
 {
     try
     {
         deviceuser item = new deviceuser();
         item.DeviceUserID = deviceUserDto.DeviceUserID;
         item.DeviceID     = deviceUserDto.DeviceID;
         item.UserID       = deviceUserDto.UserID;
         using (UnitOfWork unitofWork = new UnitOfWork())
         {
             unitofWork.GetRepository <deviceuser>().Update(item);
             unitofWork.saveChanges();
             return(new ResultHelper(true, item.DeviceUserID, ResultHelper.SuccessMessage));
         }
     }
     catch (Exception ex)
     {
         return(new ResultHelper(false, 0, ResultHelper.UnSuccessMessage));
     }
 }
Пример #3
0
        public DeviceUserDto GetDeviceUser(int deviceUserID)
        {
            try
            {
                using (UnitOfWork unitofWork = new UnitOfWork())
                {
                    deviceuser item = new deviceuser();
                    item = unitofWork.GetRepository <deviceuser>().GetById(x => x.DeviceUserID == deviceUserID);
                    DeviceUserDto deviceUserDto = new DeviceUserDto();
                    deviceUserDto.DeviceID     = item.DeviceID.Value;
                    deviceUserDto.DeviceUserID = item.DeviceUserID;
                    deviceUserDto.UserID       = item.UserID.Value;

                    return(deviceUserDto);
                }
            }
            catch (Exception ex)
            {
                return(null);
            }
        }
Пример #4
0
 public List <DeviceUserDto> GetAllDeviceUser()
 {
     try
     {
         List <DeviceUserDto> list = new List <DeviceUserDto>();
         using (UnitOfWork unitofWork = new UnitOfWork())
         {
             var query = (from du in unitofWork.GetRepository <deviceuser>().Select(null, null)
                          join u in unitofWork.GetRepository <user>().Select(null, null) on du.UserID equals u.UserID
                          join d in unitofWork.GetRepository <device>().Select(null, null) on du.DeviceID equals d.DeviceID
                          select new
             {
                 dUserID = du.UserID,
                 UserID = u.UserID,
                 FullName = u.Name + " " + u.SurName,
                 DeviceID = d.DeviceID,
                 DName = d.Name
             });
             foreach (var item in query)
             {
                 DeviceUserDto deviceUserDto = new DeviceUserDto();
                 deviceUserDto.DeviceUserID     = item.dUserID.Value;
                 deviceUserDto.UserDto          = new UserDto();
                 deviceUserDto.UserID           = item.UserID;
                 deviceUserDto.UserDto.FullName = item.FullName;
                 deviceUserDto.DeviceDto        = new DeviceDto();
                 deviceUserDto.DeviceID         = item.DeviceID;
                 deviceUserDto.DeviceDto.Name   = item.DName;
                 list.Add(deviceUserDto);
             }
             return(list);
         }
     }
     catch
     {
         return(null);
     }
 }
Пример #5
0
 public string SetDeviceUser(DeviceUserDto deviceUserDto)
 {
     return(JsonConvert.SerializeObject(deviceUserLogic.SetDeviceUser(deviceUserDto)));
 }