Пример #1
0
        public ResponseObject <bool> UpdateDeviceForAgency(DeviceAPIViewModel model)
        {
            var deviceService = this.Service <IDeviceService>();

            var result = deviceService.UpdateDeviceForAgency(model);

            return(result);
        }
Пример #2
0
        public ResponseObject <bool> CreateDevice(DeviceAPIViewModel model)
        {
            var deviceService = this.Service <IDeviceService>();

            var result = deviceService.CreateDevice(model);

            return(result);
        }
Пример #3
0
 public ResponseObject <DeviceAPIViewModel> ViewDetail(int device_id)
 {
     try
     {
         var deviceRepo = DependencyUtils.Resolve <IDeviceRepository>();
         var device     = deviceRepo.GetActive().SingleOrDefault(a => a.DeviceId == device_id);
         if (device != null)
         {
             var deviceAPIViewModel = new DeviceAPIViewModel
             {
                 DeviceId          = device.DeviceId,
                 DeviceName        = device.DeviceName,
                 AgencyId          = device.AgencyId,
                 CompanyId         = device.Agency.CompanyId,
                 CompanyName       = device.Agency.Company.CompanyName,
                 DeviceTypeId      = device.DeviceTypeId,
                 DeviceTypeName    = device.DeviceType.DeviceTypeName,
                 DeviceCode        = device.DeviceCode,
                 GuarantyStartDate = device.GuarantyStartDate != null?device.GuarantyStartDate.Value.ToString("dd/MM/yyyy") : string.Empty,
                                         GuarantyEndDate                                                                                        = device.GuarantyEndDate != null?device.GuarantyEndDate.Value.ToString("dd/MM/yyyy") : string.Empty,
                                                                                                  Ip                                            = device.Ip,
                                                                                                  Port                                          = device.Port,
                                                                                                  DeviceAccount                                 = device.DeviceAccount,
                                                                                                  DevicePassword                                = device.DevicePassword,
                                                                                                  SettingDate                                   = device.SettingDate != null?device.SettingDate.Value.ToString("dd/MM/yyyy") : string.Empty,
                                                                                                                                     Other      = device.Other,
                                                                                                                                     IsDelete   = device.IsDelete,
                                                                                                                                     CreateDate = device.CreateDate.ToString("dd/MM/yyyy"),
                                                                                                                                     UpdateDate = device.UpdateDate != null?device.UpdateDate.Value.ToString("dd/MM/yyyy") : string.Empty,
             };
             return(new ResponseObject <DeviceAPIViewModel> {
                 IsError = false, ObjReturn = deviceAPIViewModel, SuccessMessage = "Lấy chi tiết thành công"
             });
         }
         return(new ResponseObject <DeviceAPIViewModel> {
             IsError = true, WarningMessage = "Không tồn tại thiết bị này"
         });
     }
     catch (Exception e)
     {
         return(new ResponseObject <DeviceAPIViewModel> {
             IsError = true, WarningMessage = "Không tồn tại thiết bị này", ObjReturn = null, ErrorMessage = e.ToString()
         });
     }
 }
Пример #4
0
        public ResponseObject <bool> CreateDevice(DeviceAPIViewModel model)
        {
            try
            {
                var deviceRepo = DependencyUtils.Resolve <IDeviceRepository>();
                var device     = deviceRepo.GetActive(p => p.DeviceCode == model.DeviceCode).SingleOrDefault();
                if (device != null)
                {
                    return(new ResponseObject <bool> {
                        IsError = true, WarningMessage = "Trùng mã thiết bị vui lòng nhập lại", ObjReturn = false
                    });
                }

                var createDevice = new Device();
                createDevice.DeviceTypeId      = model.DeviceTypeId;
                createDevice.AgencyId          = model.AgencyId;
                createDevice.DeviceName        = model.DeviceName;
                createDevice.DeviceCode        = model.DeviceCode;
                createDevice.GuarantyStartDate = model.GuarantyStartDate.ToDateTime();
                createDevice.GuarantyEndDate   = model.GuarantyEndDate.ToDateTime();
                createDevice.Ip             = model.Ip;
                createDevice.Port           = model.Port;
                createDevice.DeviceAccount  = model.DeviceAccount;
                createDevice.DevicePassword = model.DevicePassword;
                createDevice.SettingDate    = model.SettingDate.ToDateTime();
                createDevice.Other          = model.Other;
                createDevice.IsDelete       = false;
                createDevice.CreateDate     = DateTime.UtcNow.AddHours(7);

                deviceRepo.Add(createDevice);

                deviceRepo.Save();
                return(new ResponseObject <bool> {
                    IsError = false, SuccessMessage = "Thêm loại thiết bị thành công", ObjReturn = true
                });
            }
            catch (Exception ex)
            {
                return(new ResponseObject <bool> {
                    IsError = true, WarningMessage = "Thêm loại thiết bị thất bại", ErrorMessage = ex.ToString(), ObjReturn = false
                });
            }
        }
Пример #5
0
        public ResponseObject <bool> UpdateDeviceForAgency(DeviceAPIViewModel model)
        {
            try
            {
                var deviceRepo   = DependencyUtils.Resolve <IDeviceRepository>();
                var updateDevice = deviceRepo.GetActive().SingleOrDefault(a => a.DeviceId == model.DeviceId);

                if (updateDevice != null)
                {
                    updateDevice.DeviceTypeId      = model.DeviceTypeId;
                    updateDevice.DeviceName        = model.DeviceName;
                    updateDevice.DeviceCode        = model.DeviceCode;
                    updateDevice.GuarantyStartDate = model.GuarantyStartDate.ToDateTime();
                    updateDevice.GuarantyEndDate   = model.GuarantyEndDate.ToDateTime();
                    updateDevice.Ip             = model.Ip;
                    updateDevice.Port           = model.Port;
                    updateDevice.DeviceAccount  = model.DeviceAccount;
                    updateDevice.DevicePassword = model.DevicePassword;
                    updateDevice.Other          = model.Other;
                    updateDevice.UpdateDate     = DateTime.UtcNow.AddHours(7);

                    deviceRepo.Edit(updateDevice);
                    deviceRepo.Save();
                    return(new ResponseObject <bool> {
                        IsError = false, SuccessMessage = "Chỉnh sửa thiết bị thành công", ObjReturn = true
                    });
                }

                return(new ResponseObject <bool> {
                    IsError = true, WarningMessage = "Chỉnh sửa thiết bị thất bại", ObjReturn = false
                });
            }
            catch (Exception e)
            {
                return(new ResponseObject <bool> {
                    IsError = true, WarningMessage = "Chỉnh sửa thiết bị thất bại", ObjReturn = false, ErrorMessage = e.ToString()
                });
            }
        }
        public HttpResponseMessage UpdateDevice(DeviceAPIViewModel model)
        {
            var result = _deviceDomain.UpdateDeviceForAgency(model);

            return(Request.CreateResponse(HttpStatusCode.OK, result));
        }
        public ActionResult CreateDevice(DeviceAPIViewModel model)
        {
            var result = _deviceDomain.CreateDevice(model);

            return(Json(new { result }, JsonRequestBehavior.AllowGet));
        }
Пример #8
0
 public ResponseObject <DeviceAPIViewModel> GetDeviceDetailByDeviceCode(string deviceCode)
 {
     try
     {
         var ticketList = new List <TicketAPIViewModel>();
         var deviceRepo = DependencyUtils.Resolve <IDeviceRepository>();
         var ticketRepo = DependencyUtils.Resolve <ITicketRepository>();
         var device     = deviceRepo.GetActive().SingleOrDefault(a => a.DeviceCode == deviceCode);
         var ticket     = ticketRepo.GetActive().Where(t => t.DeviceId == device.DeviceId);
         if (device != null)
         {
             if (ticket != null)
             {
                 foreach (var ticketItem in ticket)
                 {
                     var ticketViewModel = new TicketAPIViewModel
                     {
                         TicketId        = ticketItem.TicketId,
                         DeviceId        = ticketItem.DeviceId,
                         RequestId       = ticketItem.RequestId,
                         ServiceItemName = ticketItem.Request.ServiceItem.ServiceItemName,
                         Desciption      = ticketItem.Desciption,
                         CreateDate      = ticketItem.CreateDate.ToString("dd/MM/yyyy")
                     };
                     ticketList.Add(ticketViewModel);
                 }
             }
             var deviceAPIViewModel = new DeviceAPIViewModel
             {
                 DeviceId          = device.DeviceId,
                 DeviceName        = device.DeviceName,
                 AgencyId          = device.AgencyId,
                 AgencyName        = device.Agency.AgencyName,
                 CompanyId         = device.Agency.CompanyId,
                 CompanyName       = device.Agency.Company.CompanyName,
                 DeviceTypeId      = device.DeviceTypeId,
                 DeviceTypeName    = device.DeviceType.DeviceTypeName,
                 DeviceCode        = device.DeviceCode,
                 GuarantyStartDate = device.GuarantyStartDate != null?device.GuarantyStartDate.Value.ToString("dd/MM/yyyy") : string.Empty,
                                         GuarantyEndDate = device.GuarantyEndDate != null?device.GuarantyEndDate.Value.ToString("dd/MM/yyyy") : string.Empty,
                                                               GuarantyStatus = device.GuarantyEndDate != null && device.GuarantyEndDate.Value.Date >= DateTime.Now.Date ? "Còn bảo hành" : "Hết bảo hành",
                                                               Ip             = device.Ip,
                                                               Port           = device.Port,
                                                               DeviceAccount  = device.DeviceAccount,
                                                               DevicePassword = device.DevicePassword,
                                                               SettingDate    = device.SettingDate.Value.ToString("dd/MM/yyyy"),
                                                               Other          = device.Other,
                                                               TicketList     = ticketList,
                                                               IsDelete       = device.IsDelete,
                                                               CreateDate     = device.CreateDate.ToString("dd/MM/yyyy"),
                                                               UpdateDate     = device.UpdateDate.Value.ToString("dd/MM/yyyy"),
             };
             return(new ResponseObject <DeviceAPIViewModel> {
                 IsError = false, ObjReturn = deviceAPIViewModel, SuccessMessage = "Lấy chi tiết thành công"
             });
         }
         return(new ResponseObject <DeviceAPIViewModel> {
             IsError = true, WarningMessage = "Không tồn tại thiết bị này"
         });
     }
     catch (Exception e)
     {
         return(new ResponseObject <DeviceAPIViewModel> {
             IsError = true, WarningMessage = "Không tồn tại thiết bị này", ObjReturn = null, ErrorMessage = e.ToString()
         });
     }
 }