/// <summary>Save DAR for QRC Type /// <CreatedFor>For Insert QRC Type</CreatedFor> /// <CreatedBy>Bhusha n Dod</CreatedBy> /// <CreatedOn>Feb-13-2015</CreatedOn> /// </summary> /// <param name="obj"></param> /// <returns></returns> public ServiceDARModel SaveDARDetails(ServiceDARModel obj) { ObjUserRepository = new UserRepository(); objDARRepository = new DARRepository(); workorderEMSEntities _workorderEMSEntities = new workorderEMSEntities(); bool IsContinuesWOExist = false; string startTimeDAR = ""; string endTimeDAR = ""; string activityString = string.Empty; string activityStringForWONumber = string.Empty; try { if (obj.LocationId > 0 && obj.ServiceAuthKey != null) { var authuser = ObjUserRepository.GetSingleOrDefault(x => x.ServiceAuthKey == obj.ServiceAuthKey && x.IsDeleted == false); if (obj.ActivityDetails != null) { activityString = obj.ActivityDetails.Substring(obj.ActivityDetails.LastIndexOf(',') + 1); activityStringForWONumber = activityString.Substring(activityString.LastIndexOf('r') + 1); } //322 and 323 is used for continues pause and resume var IsPauseResume = obj.TaskType == Convert.ToInt64(ContinuesPauseResume.Pause) ? true : obj.TaskType == Convert.ToInt64(ContinuesPauseResume.Resume) ? true : false; if (authuser != null && authuser.UserId > 0 && obj.TaskType != 280) { //TO find Any continues WO complete before Notification Arrival var clientdt = DateTime.UtcNow.GetClientDateTimeNow(); //flag status for if user filter record in time span so to date is till midnight. bool isUTCDay = true; DateTime _fromDate = clientdt.Date; DateTime _toDate = clientdt.AddDays(1).Date; var todayDARDetails = _workorderEMSEntities.DARDetails.Where(x => x.UserId == authuser.UserId && x.LocationId == obj.LocationId && x.IsDeleted == false && x.CreatedOn >= _fromDate && (x.TaskType == 320 || x.TaskType == 321) && x.CreatedOn <= _toDate).ToList(); foreach (var item in todayDARDetails) { var darActivity = item.ActivityDetails; var stringCon = darActivity.Substring(darActivity.LastIndexOf(',') + 1); var stringCon1 = stringCon.Substring(stringCon.LastIndexOf('r') + 1); if (activityStringForWONumber == stringCon1) { IsContinuesWOExist = true; startTimeDAR = item.StartTime.ToString(); endTimeDAR = item.EndTime.ToString(); } } if (IsContinuesWOExist == true && IsPauseResume == false) { if (startTimeDAR != "" && endTimeDAR == "") { obj.Response = Convert.ToInt32(ServiceResponse.NoRecord, CultureInfo.CurrentCulture); obj.ResponseMessage = CommonMessage.AlreadyContinuesWOStart(activityStringForWONumber); } else if (startTimeDAR == "" && endTimeDAR != "") { obj.Response = Convert.ToInt32(ServiceResponse.NoRecord, CultureInfo.CurrentCulture); obj.ResponseMessage = CommonMessage.AlreadyContinuesWOComplete(activityStringForWONumber); } } else { //obj.ActivityDetails = DarMessage.QrcVehicleCleaning(obj.UserName); var result = objDARRepository.SaveDARDetails(obj); if (result != null && result > 0) { obj.Response = Convert.ToInt32(ServiceResponse.SuccessResponse, CultureInfo.CurrentCulture); obj.DARId = result; obj.ResponseMessage = CommonMessage.SaveSuccessMessage(); } else { obj.Response = Convert.ToInt32(ServiceResponse.ExeptionResponse, CultureInfo.CurrentCulture); obj.DARId = result; obj.ResponseMessage = CommonMessage.WrongParameterMessage(); } } } else if (authuser != null && authuser.UserId > 0 && obj.TaskType == 280) { var objLoginLogRepository = new LoginLogRepository(); obj.ActivityDetails = DarMessage.ShiftEnd(obj.UserName); var result = objDARRepository.SaveDARDetails(obj); if (result != null && result > 0) { var loginlog = objLoginLogRepository.GetSingleOrDefault(x => x.UserID == authuser.UserId && x.LogId == obj.LogId && x.IsDeleted == false && x.IsActive == true); if (loginlog.LogId != 0) { loginlog.IsActive = false; loginlog.ShiftEnd = DateTime.Now; objLoginLogRepository.Update(loginlog); objLoginLogRepository.SaveChanges(); } var data = ObjUserRepository.GetSingleOrDefault(v => v.UserId == obj.UserId && v.IsDeleted == false); if (data != null) { data.ModifiedBy = obj.UserId; data.ModifiedDate = DateTime.UtcNow; data.IdleTimeLimit = Convert.ToDateTime("00:30"); ObjUserRepository.Update(data); obj.Response = Convert.ToInt32(ServiceResponse.SuccessResponse, CultureInfo.CurrentCulture); obj.DARId = result; obj.ResponseMessage = CommonMessage.SaveSuccessMessage(); } } else { obj.Response = Convert.ToInt32(ServiceResponse.ExeptionResponse, CultureInfo.CurrentCulture); obj.DARId = result; obj.ResponseMessage = CommonMessage.WrongParameterMessage(); } } else { obj.Response = Convert.ToInt32(ServiceResponse.InvalidSessionResponse, CultureInfo.CurrentCulture); obj.ResponseMessage = CommonMessage.InvalidUser(); } } else { obj.Response = Convert.ToInt32(ServiceResponse.FailedResponse, CultureInfo.CurrentCulture); obj.ResponseMessage = CommonMessage.WrongParameterMessage(); } } catch (Exception) { throw; } return(obj); }
/// <summary>Save DAR for QRC Type /// <CreatedFor>For Insert QRC Type</CreatedFor> /// <CreatedBy>Bhushan Dod</CreatedBy> /// <CreatedOn>Feb-13-2015</CreatedOn> /// </summary> /// <param name="obj"></param> /// <returns></returns> public ServiceDARModel SaveDARDetails(ServiceDARModel obj) { ObjUserRepository = new UserRepository(); objDARRepository = new DARRepository(); try { if (obj.LocationId > 0 && obj.ServiceAuthKey != null) { var authuser = ObjUserRepository.GetSingleOrDefault(x => x.ServiceAuthKey == obj.ServiceAuthKey && x.IsDeleted == false); if (authuser != null && authuser.UserId > 0 && obj.TaskType != 280) { //obj.ActivityDetails = DarMessage.QrcVehicleCleaning(obj.UserName); var result = objDARRepository.SaveDARDetails(obj); if (result != null && result > 0) { obj.Response = Convert.ToInt32(ServiceResponse.SuccessResponse, CultureInfo.CurrentCulture); obj.DARId = result; obj.ResponseMessage = CommonMessage.SaveSuccessMessage(); } else { obj.Response = Convert.ToInt32(ServiceResponse.ExeptionResponse, CultureInfo.CurrentCulture); obj.DARId = result; obj.ResponseMessage = CommonMessage.WrongParameterMessage(); } } else if (authuser != null && authuser.UserId > 0 && obj.TaskType == 280) { obj.ActivityDetails = DarMessage.ShiftEnd(obj.UserName); var result = objDARRepository.SaveDARDetails(obj); if (result != null && result > 0) { var data = ObjUserRepository.GetSingleOrDefault(v => v.UserId == obj.UserId && v.IsDeleted == false); if (data != null) { data.ModifiedBy = obj.UserId; data.ModifiedDate = DateTime.UtcNow; data.IdleTimeLimit = Convert.ToDateTime("00:30"); ObjUserRepository.Update(data); obj.Response = Convert.ToInt32(ServiceResponse.SuccessResponse, CultureInfo.CurrentCulture); obj.DARId = result; obj.ResponseMessage = CommonMessage.SaveSuccessMessage(); } } else { obj.Response = Convert.ToInt32(ServiceResponse.ExeptionResponse, CultureInfo.CurrentCulture); obj.DARId = result; obj.ResponseMessage = CommonMessage.WrongParameterMessage(); } } else { obj.Response = Convert.ToInt32(ServiceResponse.InvalidSessionResponse, CultureInfo.CurrentCulture); obj.ResponseMessage = CommonMessage.InvalidUser(); } } else { obj.Response = Convert.ToInt32(ServiceResponse.FailedResponse, CultureInfo.CurrentCulture); obj.ResponseMessage = CommonMessage.WrongParameterMessage(); } } catch (Exception) { throw; } return(obj); }