public MyDBModels.DateWorkList getDataById(int id) { var db = new MyDBModels.DB(); MyDBModels.DateWorkList dateModel = db.dateWorkList.Where(b => b.DateId == id).FirstOrDefault(); return(dateModel); }
public List <FullGasList> getGasListData(int id) { var db = new MyDBModels.DB(); List <FullGasList> fullListJoin = db.bus.Join(db.gasList, b => b.BusId, gas => gas.BusId, (b, gas) => new FullGasList { Bus = new BusModel { BusId = b.BusId, BusNumber = b.BusNumber, Model = b.Model, }, GasBlank = new GasListModel { BusId = gas.BusId, GasListId = gas.GasListId, CostGas = gas.CostGas, CountLitre = gas.CountLitre, TypeGas = gas.TypeGas, TimeGet = gas.TimeGet } }).ToList(); List <FullGasList> fullListResult = new List <FullGasList>(); fullListResult.AddRange(fullListJoin.Where(g => g.GasBlank.BusId == id).ToList()); return(fullListResult); }
public List <MyDBModels.DateWorkList> getListData() { var db = new MyDBModels.DB(); List <MyDBModels.DateWorkList> listData = db.dateWorkList.ToList(); return(listData); }
public MyDBModels.Bus getDataById(int id) { var db = new MyDBModels.DB(); MyDBModels.Bus busModel = db.bus.Where(b => b.BusId == id).FirstOrDefault(); return(busModel); }
public List <FullRepairList> getRepairListData(int id) { var db = new MyDBModels.DB(); List <FullRepairList> fullListJoin = db.bus.Join(db.repairList, b => b.BusId, rep => rep.BusId, (b, rep) => new FullRepairList { Bus = new BusModel { BusId = b.BusId, BusNumber = b.BusNumber, Model = b.Model, BusCondition = b.BusCondition }, RepairBlank = new RepairListModel { BusId = b.BusId, ServiceListId = rep.ServiceListId, BusCondition = rep.BusCondition, TimeGet = rep.TimeGet } }).ToList(); List <FullRepairList> fullListResult = new List <FullRepairList>(); fullListResult.AddRange(fullListJoin.Where(r => r.RepairBlank.BusId == id).ToList()); return(fullListResult); }
public List <MyDBModels.Bus> getListData() { var db = new MyDBModels.DB(); List <MyDBModels.Bus> listData = db.bus.ToList(); return(listData); }
private PreviewProfileModel formatProfileData(int userId, ProfileStatisticsModel profileStatisticsModel) { var db = new MyDBModels.DB(); var countUnreadMessages = 0; var countGroups = 0; var dateUtils = new DateUtils(); var userModel = db.user.Where(u => u.UserId == userId).First(); var profileModel = db.profile.Where(p => p.ProfileId == userModel.ProfileId).First(); var communicationIdArray = userModel.CommunicationIdArray; var communicationDataAccess = new CommunicationDataAccess(); communicationIdArray.ToList().ForEach(delegate(int communicationId) { var communicationModelDb = db.communication.Where(c => c.CommunicationId == communicationId).First(); if (IsUnreadCommunication(communicationModelDb.MessageIdArray, profileModel.ProfileId)) { countUnreadMessages++; } }); PreviewProfileModel previewProfileModel = new PreviewProfileModel(); previewProfileModel.FullName = String.Format("{0} {1}", profileModel.Name, profileModel.LastName); previewProfileModel.PhotoUrl = profileModel.PhotoUrl; previewProfileModel.TimeLastActive = profileModel.TimeLastActive;//dateUtils.calculateStateLastActivity(profileModel.TimeLastActive); previewProfileModel.CountRequestedFriends = userModel.FriendPossibleIdArray.Count();; previewProfileModel.CountUnreadMessages = countUnreadMessages; previewProfileModel.CountRequestedGroups = countGroups; previewProfileModel.ProfileStatistics = profileStatisticsModel; return(previewProfileModel); }
private MyDBModels.ProfileStatistics getStatisticsByUserId(MyDBModels.DB db, int userId) { var userModel = db.user.Where(u => u.UserId == userId).First(); var profileModel = db.profile.Where(p => p.ProfileId == userModel.ProfileId).First(); return(db.profileStatistics.Where(ps => ps.ProfileStatisticsId == profileModel.ProfileStatisticsId).First()); }
public List <string> postSignIn(Models.AccountModel accountModel) { var db = new MyDBModels.DB(); string cryptName = EncryptClass.DESEncrypt(accountModel.Secondname); string cryptPassword = EncryptClass.MD5Hash(accountModel.Password); List <string> result = new List <string>(); result.Clear(); MyDBModels.Account accountFinal = db.account.Where(b => b.LoginId == cryptName && b.PasswordWorker == cryptPassword).FirstOrDefault(); if (accountFinal != null) { result.Add(EncryptClass.DESDecrypt(accountFinal.LoginId)); result.Add(EncryptClass.DESDecrypt(accountFinal.RoleWorker)); result.Add(EncryptClass.DESDecrypt(accountFinal.NumberWorker)); int number = int.Parse(EncryptClass.DESDecrypt(accountFinal.NumberWorker)); if (number > 100) { MyDBModels.Dispatcher dispatcher = db.dispatcher.Where(b => b.DispatcherNumber == number).FirstOrDefault(); result.Add(dispatcher.Image); } else { MyDBModels.Driver driver = db.driver.Where(b => b.DriverNumber == number).FirstOrDefault(); result.Add(driver.Image); } } else { result.Add("NOT OK"); } return(result); }
private void deleteFriendFromDb(MyDBModels.DB db, MyDBModels.User fromDeleteUserModel, int deleteProfileId) { var friendArrayIdUpdate = fromDeleteUserModel.FriendIdArray.ToList(); friendArrayIdUpdate.Remove(deleteProfileId); fromDeleteUserModel.FriendIdArray = friendArrayIdUpdate.ToArray(); var dataAccess = new CommunicationDataAccess(); int communicationId = dataAccess.searchCommunication(fromDeleteUserModel.ProfileId, deleteProfileId); var communicationIdArray = fromDeleteUserModel.CommunicationIdArray; var communicationIdList = communicationIdArray.ToList(); communicationIdList.Remove(communicationId); fromDeleteUserModel.CommunicationIdArray = communicationIdList.ToArray(); if (fromDeleteUserModel.CommunicationPinIdArray.Contains(communicationId)) { var communicationPinIdArray = fromDeleteUserModel.CommunicationPinIdArray; var communicationPinIdList = communicationPinIdArray.ToList(); communicationPinIdList.Remove(communicationId); fromDeleteUserModel.CommunicationPinIdArray = communicationPinIdList.ToArray(); } db.SaveChanges(); }
public MyDBModels.WorkList getDataById(int id) { var db = new MyDBModels.DB(); MyDBModels.WorkList workModel = db.workList.Where(b => b.WorkListId == id).FirstOrDefault(); return(workModel); }
public List <CommunicationDataModel> getCommunicationListByPart(int userId, int count, int number) { var db = new MyDBModels.DB(); var user = db.user.Where(u => u.UserId == userId).First(); var myProfileId = user.ProfileId; var myCommunicationListDB = new List <MyDBModels.Communication>(); var communicationDataModelList = new List <CommunicationDataModel>(); var partCommunicationListDb = new List <MyDBModels.Communication>(); user.CommunicationIdArray.ToList().ForEach(delegate(int communicationId) { myCommunicationListDB.Add(db.communication.Where(c => c.CommunicationId == communicationId).First()); }); var countProfileDb = myCommunicationListDB.Count(); for (int i = (number - 1) * count; i < count * number; i++) { if (i < countProfileDb) { partCommunicationListDb.Add(myCommunicationListDB.ElementAt(i)); } } foreach (MyDBModels.Communication communication in partCommunicationListDb) { communicationDataModelList.Add(createCommunicationDataFromDb(communication, myProfileId, 1)); } return(communicationDataModelList); }
public void settingAddProfileToCommunication(int userId, string keyDialog, int profileId) { var db = new MyDBModels.DB(); var dateUtils = new DateUtils(); var communicationModel = db.communication.Where(c => c.KeyDialog == keyDialog).First(); var participantProfileIdList = communicationModel.ParticipantProfileIdArray.ToList(); participantProfileIdList.Add(profileId); communicationModel.ParticipantProfileIdArray = participantProfileIdList.ToArray(); var addProfileTimestampList = communicationModel.AddProfileTimestampArray.ToList(); addProfileTimestampList.Add(dateUtils.DateTimeToUnixTimeStamp(DateTime.Now)); communicationModel.AddProfileTimestampArray = addProfileTimestampList.ToArray(); var communicationIdArray = db.user.Where(u => u.ProfileId == profileId).First().CommunicationIdArray; var communicationIdList = communicationIdArray.ToList(); communicationIdList.Add(communicationModel.CommunicationId); db.user.Where(u => u.ProfileId == profileId).First().CommunicationIdArray = communicationIdList.ToArray(); db.SaveChanges(); var nameAddedProfile = db.profile.Where(p => p.ProfileId == profileId).First().Name; var messageAddId = createSystemMessage(userId, String.Format("{0} {1}", "Added user", nameAddedProfile), 2); var messageIdList = communicationModel.MessageIdArray.ToList(); messageIdList.Add(messageAddId); communicationModel.MessageIdArray = messageIdList.ToArray(); db.SaveChanges(); }
public PreviewProfileModel logInUserCheck(string basic) { var db = new MyDBModels.DB(); try { var dataAccess = new ProfileDataAccess(); var userId = db.signUp.Where(s => s.BaseCode == basic).First().UserId; var profileId = db.user.Where(u => u.UserId == userId).First().ProfileId; var profileDbModel = db.profile.Where(p => p.ProfileId == profileId).First(); var profileModel = new ProfileModel(); var dateUtils = new DateUtils(); return(dataAccess.previewProfile(userId, 1)); /* * profileModel.Name = profileDbModel.Name; * profileModel.LastName = profileDbModel.LastName; * profileModel.City = profileDbModel.City; * profileModel.PhotoUrl = profileDbModel.PhotoUrl; * profileModel.Phone = profileDbModel.Phone; * profileModel.Email = profileDbModel.Email; * profileModel.TimeLastActive = profileDbModel.TimeLastActive;// dateUtils.calculateStateLastActivity(profileDbModel.TimeLastActive); * * return profileModel;*/ } catch (Exception exc) { return(null); } }
public void deleteCommunication(int userId, string keyDialog) { var db = new MyDBModels.DB(); var communicationModel = db.communication.Where(c => c.KeyDialog == keyDialog).First(); var userModel = db.user.Where(u => u.UserId == userId).First(); var profileId = userModel.ProfileId; var dateUtils = new DateUtils(); // removeCommunication(db, communicationModel, userModel.ProfileId); int indexProfile = Array.IndexOf(communicationModel.ParticipantProfileIdArray, profileId); var addProfileTimestampList = communicationModel.AddProfileTimestampArray.ToList(); var timestamp = addProfileTimestampList.ElementAt(indexProfile); addProfileTimestampList.Remove(timestamp); addProfileTimestampList.Insert(indexProfile, dateUtils.DateTimeToUnixTimeStamp(DateTime.Now)); communicationModel.AddProfileTimestampArray = addProfileTimestampList.ToArray(); db.SaveChanges(); var communicationIdArray = userModel.CommunicationIdArray; var communicationIdList = communicationIdArray.ToList(); communicationIdList.Remove(communicationModel.CommunicationId); userModel.CommunicationIdArray = communicationIdList.ToArray(); if (db.user.Where(u => u.ProfileId == profileId).First().CommunicationPinIdArray.Contains(communicationModel.CommunicationId)) { var communicationPinIdArray = userModel.CommunicationPinIdArray; var communicationPinIdList = communicationPinIdArray.ToList(); communicationPinIdList.Remove(communicationModel.CommunicationId); userModel.CommunicationPinIdArray = communicationPinIdList.ToArray(); } db.SaveChanges(); }
public MyDBModels.GasList getDataById(int id) { var db = new MyDBModels.DB(); MyDBModels.GasList gasModel = db.gasList.Where(b => b.GasListId == id).FirstOrDefault(); return(gasModel); }
public MyDBModels.Driver getDataById(int id) { var db = new MyDBModels.DB(); MyDBModels.Driver driverModel = db.driver.Where(b => b.DriverId == id).FirstOrDefault(); return(driverModel); }
public List <MyDBModels.Driver> getListData() { var db = new MyDBModels.DB(); List <MyDBModels.Driver> listData = db.driver.ToList(); return(listData); }
public void postWork(Models.WorkListModel value) { var db = new MyDBModels.DB(); MyDBModels.WorkList workList = new MyDBModels.WorkList(); workList.DriverId = value.DriverId; workList.BusId = value.BusId; workList.SecondNameDispatcher = value.SecondNameDispatcher; workList.DateAction = value.DateAction; db.workList.Add(workList); MyDBModels.Bus busModel = db.bus.Where(b => b.BusId == value.BusId).FirstOrDefault(); string title = "Bus: " + busModel.BusNumber.ToString() + "/" + busModel.Model; string info = "Date: " + value.DateAction + "\nDispatcher: " + value.SecondNameDispatcher; string number = EncryptClass.DESEncrypt(db.driver.Where(b => b.DriverId == value.DriverId).FirstOrDefault().DriverNumber.ToString()); MyDBModels.Account accountModel = db.account.Where(b => b.NumberWorker == number).FirstOrDefault(); string token = accountModel.Token; sendRequestToFirebase("\"" + title + "\"", "\"" + info + "\"", "\"" + token + "\""); db.SaveChanges(); }
private void removeCommunication(MyDBModels.DB db, MyDBModels.Communication communicationModel, int profileId) { var dateUtils = new DateUtils(); int indexRemoveProfile = Array.IndexOf(communicationModel.ParticipantProfileIdArray, profileId); var participantProfileIdList = communicationModel.ParticipantProfileIdArray.ToList(); participantProfileIdList.Remove(profileId); communicationModel.ParticipantProfileIdArray = participantProfileIdList.ToArray(); var addProfileTimestampList = communicationModel.AddProfileTimestampArray.ToList(); addProfileTimestampList.Remove(communicationModel.AddProfileTimestampArray.ElementAt(indexRemoveProfile)); communicationModel.AddProfileTimestampArray = addProfileTimestampList.ToArray(); var userModel = db.user.Where(u => u.ProfileId == profileId).First(); var communicationIdArray = userModel.CommunicationIdArray; var communicationIdList = communicationIdArray.ToList(); communicationIdList.Remove(communicationModel.CommunicationId); userModel.CommunicationIdArray = communicationIdList.ToArray(); if (db.user.Where(u => u.ProfileId == profileId).First().CommunicationPinIdArray.Contains(communicationModel.CommunicationId)) { var communicationPinIdArray = userModel.CommunicationPinIdArray; var communicationPinIdList = communicationPinIdArray.ToList(); communicationPinIdList.Remove(communicationModel.CommunicationId); userModel.CommunicationPinIdArray = communicationPinIdList.ToArray(); } db.SaveChanges(); }
public List <FullGasList> getFullListDataByUser(int number) { var db = new MyDBModels.DB(); int idDriver = db.driver.Where(d => d.DriverNumber == number).FirstOrDefault().DriverId; List <MyDBModels.WorkList> work = db.workList.Where(d => d.DriverId == idDriver).ToList(); List <FullGasList> fullListJoin = db.bus.Join(db.gasList, b => b.BusId, gas => gas.BusId, (b, gas) => new FullGasList { Bus = new BusModel { BusId = b.BusId, BusNumber = b.BusNumber, Model = b.Model, }, GasBlank = new GasListModel { GasListId = gas.GasListId, CostGas = gas.CostGas, CountLitre = gas.CountLitre, TypeGas = gas.TypeGas, TimeGet = gas.TimeGet } }).ToList(); List <FullGasList> fullListResult = new List <FullGasList>(); for (int i = 0; i < work.Count; i++) { fullListResult.AddRange(fullListJoin.Where(g => g.Bus.BusId == work[i].BusId && g.GasBlank.TimeGet == work[i].DateAction).ToList()); } return(fullListResult); }
public MyDBModels.RepairList getDataById(int id) { var db = new MyDBModels.DB(); MyDBModels.RepairList repairModel = db.repairList.Where(b => b.ServiceListId == id).FirstOrDefault(); return(repairModel); }
public List <FullRepairList> getFullListDataByUser(int number) { var db = new MyDBModels.DB(); int idDriver = db.driver.Where(d => d.DriverNumber == number).FirstOrDefault().DriverId; List <MyDBModels.WorkList> work = db.workList.Where(d => d.DriverId == idDriver).ToList(); List <FullRepairList> fullListJoin = db.bus.Join(db.repairList, b => b.BusId, rep => rep.BusId, (b, rep) => new FullRepairList { Bus = new BusModel { BusId = b.BusId, BusNumber = b.BusNumber, Model = b.Model, BusCondition = b.BusCondition }, RepairBlank = new RepairListModel { ServiceListId = rep.ServiceListId, BusCondition = rep.BusCondition, TimeGet = rep.TimeGet } }).ToList(); List <FullRepairList> fullListResult = new List <FullRepairList>(); for (int i = 0; i < work.Count; i++) { fullListResult.AddRange(fullListJoin.Where(r => r.Bus.BusId == work[i].BusId && r.RepairBlank.TimeGet == work[i].DateAction).ToList()); } return(fullListResult); }
public List <MyDBModels.RepairList> getListData() { var db = new MyDBModels.DB(); List <MyDBModels.RepairList> listData = db.repairList.ToList(); return(listData); }
public void sendMessage(int userId, MessageSendModel model, string keyDialog) { var db = new MyDBModels.DB(); var user = db.user.Where(u => u.UserId == userId).First(); var profileId = user.ProfileId; var currentCommunication = db.communication.Where(c => c.KeyDialog == keyDialog).First(); MyDBModels.Message messsage = new MyDBModels.Message(); messsage.DataMessage = model.DataMessage; messsage.TimeWritten = model.TimeWritten; messsage.IsReadProfileId = new int[] { profileId }; messsage.ProfileId = profileId; messsage.TypeMessage = 1; db.message.Add(messsage); db.SaveChanges(); var messageIdArray = currentCommunication.MessageIdArray.ToList(); messageIdArray.Add(db.message.Where(m => m.ProfileId == profileId && m.TimeWritten == model.TimeWritten).FirstOrDefault().MessageId);//OrderByDescending need? currentCommunication.MessageIdArray = messageIdArray.ToArray(); var dataAccess = new CommunicationDataAccess(); if (!currentCommunication.IsGroup) { var friendProfileId = currentCommunication.ParticipantProfileIdArray.Where(p => p != profileId).First(); dataAccess.searchAndConnectOldCommunication(profileId, friendProfileId); } db.SaveChanges(); }
private bool chaeckIsReadMessage(MyDBModels.Message message, int userId) { var db = new MyDBModels.DB(); var myProfileId = db.user.Where(u => u.UserId == userId).First().ProfileId; return(!(message.ProfileId == myProfileId && message.IsReadProfileId.Count() < 2)); }
private DialogInfoModel createInfoAboutUserCommunication(MyDBModels.Communication currentCommunication, int myProfileId) { var participantProfileId = currentCommunication.ParticipantProfileIdArray; DialogInfoModel dialogInfoModel = new DialogInfoModel(); dialogInfoModel.FullName = currentCommunication.Name; dialogInfoModel.PhotoUrl = currentCommunication.PhotoUrl; var participantCount = participantProfileId.Count(); if (currentCommunication.IsGroup) { dialogInfoModel.SecondInfoCount = String.Format("{0} {1}", participantCount, "members"); dialogInfoModel.ProfileShortModelList = createProfileShortModelList(participantProfileId, currentCommunication.CreaterProfileId); } else { var dateUtils = new DateUtils(); var profileFriend = participantProfileId.Where(p => p != myProfileId).First(); var db = new MyDBModels.DB(); var profileModel = db.profile.Where(p => p.ProfileId == profileFriend).First(); dialogInfoModel.SecondInfoTime = profileModel.TimeLastActive;// dateUtils.stateLastActivityProfile(profileFriend); dialogInfoModel.ProfileId = profileFriend; } return(dialogInfoModel); }
public string stateLastActivityProfile(int profileId) { var db = new MyDBModels.DB(); var profileModel = db.profile.Where(p => p.ProfileId == profileId).First(); var lastActive = profileModel.TimeLastActive; return(calculateStateLastActivity(lastActive)); }
private void saveToken(int userId, string token) { var db = new MyDBModels.DB(); var userModel = db.user.Where(u => u.UserId == userId).First(); userModel.FirebaseToken = token; db.SaveChanges(); }
public void createCommunication(int userId, CommunicationShortModel model) { var db = new MyDBModels.DB(); var keyDailog = generateKeyDialog(); var dateUtils = new DateUtils(); var userModel = db.user.Where(u => u.UserId == userId).First(); MyDBModels.Communication communication = new MyDBModels.Communication(); communication.KeyDialog = keyDailog; communication.Name = model.Name; communication.PhotoUrl = model.PhotoUrl; communication.ParticipantProfileIdArray = model.ParticipantProfileIdArray; communication.CreaterProfileId = userModel.ProfileId; communication.AddProfileTimestampArray = Enumerable.Repeat(dateUtils.DateTimeToUnixTimeStamp(DateTime.Now), model.ParticipantProfileIdArray.Count()).ToArray(); if (model.ParticipantProfileIdArray.Count() > 2) { communication.IsGroup = true; } else if (model.ParticipantProfileIdArray.Count() < 3) { foreach (int profileId in model.ParticipantProfileIdArray) { var profile = db.profile.Where(p => p.ProfileId == profileId).First(); var searchFullName = String.Format("{0} {1}", profile.Name, profile.LastName); if (model.Name.Contains(searchFullName)) { communication.IsGroup = false; break; } else { communication.IsGroup = true; } } ; } else { communication.IsGroup = false; } var systemMessageCreateId = createSystemMessage(userId, String.Format("{0} {1}", "Created communication", model.Name), 2); communication.MessageIdArray = new int[] { systemMessageCreateId }; db.communication.Add(communication); db.SaveChanges(); int communicationId = db.communication.Where(c => c.KeyDialog == keyDailog).First().CommunicationId; model.ParticipantProfileIdArray.ToList().ForEach(delegate(int profileId) { addCommunicationToUserByProfile(db, profileId, communicationId); }); }