Esempio n. 1
0
        public async Task <IHttpActionResult> Update(GameScore score)
        {
            //Cleanup. This should be a background job.
            var badRange = AppDatabase.Scores.Where(o => o.CreatedOn < DateTime.UtcNow.Subtract(new TimeSpan(30, 0, 0, 0)));

            AppDatabase.Scores.RemoveRange(badRange);
            await AppDatabase.SaveChangesAsync();

            // Select old
            var model = await AppDatabase.Scores.OrderByDescending(o => o.Score).FirstOrDefaultAsync(o => o.UserId == UserId);


            //Update ?
            if (model != null)
            {
                //Skip if less than
                if (model.Score > score.Score)
                {
                    return(Ok());
                }

                model.Score = score.Score;
            }
            else
            {
                //Create
                AppDatabase.Scores.Add(score);
            }

            await AppDatabase.SaveChangesAsync();

            return(Ok());
        }
Esempio n. 2
0
        public App()
        {
            InitializeComponent();
            VersionTracking.Track();

            var logger = new LoggerConfiguration()
                         .WriteTo.File(Path.Combine(FileSystem.AppDataDirectory, "log.txt"),
                                       rollingInterval: RollingInterval.Day)
                         .CreateLogger();

            string databasePath = Path.Combine(FileSystem.AppDataDirectory, "app.db");
            var    database     = new AppDatabase(databasePath);

            string userSettingsPath  = Path.Combine(FileSystem.AppDataDirectory, "user_settings.json");
            var    settingsService   = new SettingsService(userSettingsPath, logger);
            var    settingsViewModel = new SettingsViewModel(settingsService);

            DependencyContainer = new Container();
            DependencyContainer.RegisterSingleton <ILogger>(() => logger);
            DependencyContainer.RegisterSingleton(() => database);
            DependencyContainer.RegisterSingleton(() => settingsService);
            DependencyContainer.RegisterSingleton(() => settingsViewModel);
            DependencyContainer.RegisterSingleton <ISettingsViewModel>(() => settingsViewModel);
            DependencyContainer.RegisterSingleton <ITrackerService, TrackerService>();
            DependencyContainer.RegisterSingleton <ITrackerLogService, TrackerLogService>();
            DependencyContainer.RegisterSingleton <TrackerViewModel>();
            DependencyContainer.RegisterSingleton <ImportViewModel>();
            DependencyContainer.RegisterSingleton <ExportViewModel>();

            MainPage = new ConductorPage();
        }
Esempio n. 3
0
        public ActionResult SetupAppraisalApprovers(AppraisalApproverModel appraisalApproverModel)
        {
            appraisalApproverModel.EntryKey = getEntryKey(appraisalApproverModel);

            /*bool duplicateEntry = LINQCalls.checkDupApproverSetup( appraisalApproverModel.EntryKey.ToUpper() );
             * if (!duplicateEntry) {
             *  TempData["ErrorMessage"] = "Error : The staff : "+ appraisalApproverModel.StaffName +" has an existing setup with the same identity";
             * }*/

            HRProfile hrprofile = LINQCalls.hrprofile(appraisalApproverModel.HRStaffName, 1);

            if (hrprofile == null)
            {
                TempData["ErrorMessage"] = "Error : You staff profile is not properly setup";
            }

            //Setup the branch
            int    inputMode = 0;
            string retVal    = new AppDatabase().insertApproverSetup(appraisalApproverModel, hrprofile, inputMode, "AppraisalDbConnectionString");

            if (!String.IsNullOrEmpty(retVal) && !retVal.Split('|')[0].Equals("0"))
            {
                TempData["ErrorMessage"] = "Error :" + retVal.Split('|')[1];
            }
            else
            {
                appraisalApproverModel = null;
            }

            TempData["appraisalApproverModel"] = appraisalApproverModel;
            return(RedirectToAction("SetupAppraisalApprovers"));
        }
Esempio n. 4
0
 private static void ProcedureParameters(SqlCommand cmd, Guid guid, string name, string description, Guid modifiedBy)
 {
     AppDatabase.AddInParameter(cmd, Procedure.Columns.PrecedureGuid, SqlDbType.UniqueIdentifier, guid);
     AppDatabase.AddInParameter(cmd, Procedure.Columns.ProcedureName, SqlDbType.NVarChar, AppShared.SafeString(name));
     AppDatabase.AddInParameter(cmd, Procedure.Columns.ProcedureDescription, SqlDbType.NVarChar, AppShared.SafeString(description));
     AppDatabase.AddInParameter(cmd, Procedure.Columns.ProcedureModifiedBy, SqlDbType.UniqueIdentifier, modifiedBy);
 }
        public IActionResult UpdateNumbers(
            [FromServices] AppDatabase db,
            [FromBody] SportEventViewModel viewModel,
            [FromQuery, FromForm] long?id = null
            )
        {
            long queryId = id ?? (long)viewModel.Id;

            SportEvent model = db.Events.Where(x => x.Id == queryId).FirstOrDefault();

            if (model is null)
            {
                return(NotFound());
            }

            model.AwayTeamOdds = viewModel.AwayTeamOdds;
            model.HomeTeamOdds = viewModel.HomeTeamOdds;
            model.DrawOdds     = viewModel.DrawOdds;

            model.AwayTeamScore = viewModel.AwayTeamScore;
            model.HomeTeamScore = viewModel.HomeTeamScore;

            db.SaveChanges();

            return(Ok());
        }
Esempio n. 6
0
        public async Task <IHttpActionResult> FacebookUpdate(AccountFacebookConnect model)
        {
            var client = new FacebookClient(model.AccessToken);

            client.AppId     = AppConfig.Settings.FacebookId;
            client.AppSecret = AppConfig.Settings.FacebookSecret;

            dynamic fbresult = client.Get("me?fields=id,email,first_name,last_name,gender,locale,link,timezone,location,picture");

            var social = await AppDatabase.UserFacebookClaims.FindAsync(fbresult.id);

            var user = await AppDatabase.Users.FindAsync(UserId);

            if (social == null)
            {
                social             = new UserFacebookClaim();
                social.Id          = fbresult.id;
                social.User        = user;
                social.UserId      = UserId;
                social.AccessToken = model.AccessToken;
                social.Provider    = APIConstants.FACEBOOK;
                AppDatabase.UserFacebookClaims.Add(social);
            }

            FacebookUpdateInternal(social, fbresult);

            await AppDatabase.SaveChangesAsync();

            Session.UpdateFrom(user);
            return(Ok(GetAccountDetails()));
        }
Esempio n. 7
0
 private static void WardParameters(SqlCommand cmd, Guid guid, string name, string description, Guid modifiedBy)
 {
     AppDatabase.AddInParameter(cmd, Ward.Columns.WardGuid, SqlDbType.UniqueIdentifier, guid);
     AppDatabase.AddInParameter(cmd, Ward.Columns.WardName, SqlDbType.NVarChar, AppShared.SafeString(name));
     AppDatabase.AddInParameter(cmd, Ward.Columns.WardDescription, SqlDbType.NVarChar, AppShared.SafeString(description));
     AppDatabase.AddInParameter(cmd, Ward.Columns.WardModifiedBy, SqlDbType.UniqueIdentifier, modifiedBy);
 }
Esempio n. 8
0
 public TablesViewModel(AppDatabase database)
 {
     this.database     = database;
     Title             = "Browse Tables";
     Tables            = new ObservableCollection <Table>();
     LoadTablesCommand = new Command(() => ExecuteLoadTablesCommand());
 }
Esempio n. 9
0
 public UsersController()
 {
     if (AppDatabase.Users == null)
     {
         AppDatabase.SeedDatabase();
     }
 }
        public ActionResult Post(BotModel model)
        {
            using (var db = new AppDatabase())
            {
                var bot = db.GetBot();

                if (bot == null)
                {
                    db.Bots.Upsert(new Database.Entities.Bot
                    {
                        Id             = 1,
                        IsEnabled      = false,
                        AccessToken    = model.AccessToken,
                        LastUpdatedUtc = DateTime.UtcNow
                    });
                }
                else
                {
                    // Reset all other parameters if token changes
                    //
                    if (bot.AccessToken != model.AccessToken)
                    {
                        bot.Username       = null;
                        bot.ChatId         = 0;
                        bot.IsEnabled      = false;
                        bot.LastUpdatedUtc = DateTime.UtcNow;
                        bot.AccessToken    = model.AccessToken;
                        db.Bots.Update(bot);
                    }
                }

                return(Ok());
            }
        }
Esempio n. 11
0
 private static void MedicineParameters(SqlCommand cmd, Guid MedicineGuid, string MedicineName, string MedicineDescription, Guid modifiedBy)
 {
     AppDatabase.AddInParameter(cmd, Medicine.Columns.MedicineGuid, SqlDbType.UniqueIdentifier, MedicineGuid);
     AppDatabase.AddInParameter(cmd, Medicine.Columns.MedicineName, SqlDbType.NVarChar, AppShared.SafeString(MedicineName));
     AppDatabase.AddInParameter(cmd, Medicine.Columns.MedicineDescription, SqlDbType.NVarChar, AppShared.ToDbValueNullable(MedicineDescription));
     AppDatabase.AddInParameter(cmd, Medicine.Columns.MedicineModifiedBy, SqlDbType.UniqueIdentifier, modifiedBy);
 }
Esempio n. 12
0
        public App()
        {
            InitializeComponent();

            AppDatabase.UpdateDatabase();
            MainPage = new MainPageMasterDetail();
        }
Esempio n. 13
0
 private static void TreatmentParameters(SqlCommand cmd, Guid guid, string name, string description, Guid modifiedBy)
 {
     AppDatabase.AddInParameter(cmd, IPDTreatment.Columns.TreatmentGuid, SqlDbType.UniqueIdentifier, guid);
     AppDatabase.AddInParameter(cmd, IPDTreatment.Columns.TreatmentName, SqlDbType.NVarChar, AppShared.SafeString(name));
     AppDatabase.AddInParameter(cmd, IPDTreatment.Columns.TreatmentDescription, SqlDbType.NVarChar, AppShared.SafeString(description));
     AppDatabase.AddInParameter(cmd, IPDTreatment.Columns.TreatmentModifiedBy, SqlDbType.UniqueIdentifier, modifiedBy);
 }
        public static void Create()
        {
            Busy = false;

            Ini = new UlIniFile(csIniFName);

            TotalLog       = new UlLogger();
            TotalLog.Path  = Path.GetFullPath(Ini.GetString("Log", "TotalPath"));
            TotalLog.FName = Ini.GetString("Log", "TotalFileName");

            DbLog       = new UlLogger();
            DbLog.Path  = Path.GetFullPath(Ini.GetString("Log", "DatabasePath"));
            DbLog.FName = Ini.GetString("Log", "DatabaseFileName");

            string connectString = Ini.GetString("Database", "ConnectString");

            DB = new AppDatabase(connectString);

            if (string.IsNullOrWhiteSpace(connectString) == true)
            {
                DB.DataSource     = Ini.GetString("Database", "DataSource");
                DB.InitialCatalog = Ini.GetString("Database", "InitialCatalog");
                DB.UserID         = Ini.GetString("Database", "UserID");
                DB.Password       = Ini.GetString("Database", "Password");
            }
            DB.Open();

            Settings = new AppSettings();
            TotalLog[ELogTag.Note] = $"Create application resource";
        }
 private static void LabInvestigationParameter(SqlCommand cmd, Guid LabInvestigationGuid, string LabInvestigationName, string LabInvestigationDescription, Guid modifiedBy)
 {
     AppDatabase.AddInParameter(cmd, LabInvestigation.Columns.LabInvestigationGuid, SqlDbType.UniqueIdentifier, LabInvestigationGuid);
     AppDatabase.AddInParameter(cmd, LabInvestigation.Columns.LabInvestigationName, SqlDbType.NVarChar, AppShared.SafeString(LabInvestigationName));
     AppDatabase.AddInParameter(cmd, LabInvestigation.Columns.LabInvestigationDescription, SqlDbType.NVarChar, AppShared.ToDbValueNullable(LabInvestigationDescription));
     AppDatabase.AddInParameter(cmd, LabInvestigation.Columns.LabInvestigationModifiedBy, SqlDbType.UniqueIdentifier, modifiedBy);
 }
Esempio n. 16
0
 private static void RoomParameters(SqlCommand cmd, Guid guid, string type, string description, Guid modifiedBy)
 {
     AppDatabase.AddInParameter(cmd, Room.Columns.RoomGuid, SqlDbType.UniqueIdentifier, guid);
     AppDatabase.AddInParameter(cmd, Room.Columns.RoomType, SqlDbType.NVarChar, AppShared.SafeString(type));
     AppDatabase.AddInParameter(cmd, Room.Columns.RoomDescription, SqlDbType.NVarChar, AppShared.SafeString(description));
     AppDatabase.AddInParameter(cmd, Room.Columns.RoomModifiedBy, SqlDbType.UniqueIdentifier, modifiedBy);
 }
Esempio n. 17
0
        public async Task <IHttpActionResult> Reset(AccountEmailReset model)
        {
            var user = await AppDatabase.Users.FirstOrDefaultAsync(o => o.Email == model.Email);

            if (user == null)
            {
                return(BadRequest("User not found"));
            }

            if (string.IsNullOrEmpty(user.Email))
            {
                return(BadRequest("User lacks a valid email address. Did you use Facebook or Twilio ?"));
            }

            var token = Strings.RandomString(6).ToLower();

            user.ModifiedOn    = DateTime.UtcNow;
            user.EmailPassword = UserPassword.Create(token);

            AppDatabase.Entry(user).State = EntityState.Modified;

            await AppDatabase.SaveChangesAsync();

            await SendTokenEmail(new UserTokenViewModel
            {
                UserId    = user.Id,
                UserEmail = user.Email,
                Token     = token,
            });

            return(Ok(GetAccountDetails()));
        }
 public EstablishmentsController()
 {
     if (AppDatabase.Establishments == null)
     {
         AppDatabase.SeedDatabase();
     }
 }
Esempio n. 19
0
        public async Task <IHttpActionResult> FacebookDisconnect(AccountFacebookDisconnect model)
        {
            var user = await AppDatabase.Users.Include(o => o.UserFacebookClaims).FirstOrDefaultAsync(o => o.Id == UserId);

            if (user == null)
            {
                return(BadRequest("User not found"));
            }


            var social = user.UserFacebookClaims.FirstOrDefault();

            if (social == null)
            {
                return(BadRequest("Social connection not found"));
            }

            if (user.UserFacebookClaims.Count() == 1 && string.IsNullOrEmpty(user.Email))
            {
                return(BadRequest("Orphan Account. Please add an email."));
            }

            AppDatabase.UserFacebookClaims.Remove(social);
            await AppDatabase.SaveChangesAsync();

            return(Ok(GetAccountDetails()));
        }
 public EntriesController()
 {
     if (AppDatabase.Entries == null)
     {
         AppDatabase.SeedDatabase();
     }
 }
Esempio n. 21
0
 public TableDetailViewModel(string name, AppDatabase database)
 {
     this.name     = name;
     this.database = database;
     userRepo      = new UserRepo(database);
     roomRepo      = new RoomRepo(database);
 }
Esempio n. 22
0
        public IActionResult Upload([FromServices] AppDatabase db)
        {
            IFormFile jsonFile = Request.Form.Files.SingleOrDefault(
                x =>
                x.Name == "export" &&
                Path.HasExtension(x.FileName) &&
                Path.GetExtension(x.FileName).Trim('.').ToLower() == "json"
                );

            if (jsonFile is null)
            {
                return(BadRequest(
                           error: "Request does not contain a single json file in 'export.'"
                           ));
            }

            string fileContent;

            using (var reader = new StreamReader(jsonFile.OpenReadStream(), Encoding.UTF8))
            {
                fileContent = reader.ReadToEnd();
            }

            SportEventViewModel[] eventViewModels =
                JsonConvert.DeserializeObject <SportEventViewModel[]>(fileContent);

            Upload_ClearDatabase(db);
            Upload_InsertData(db, eventViewModels);
            db.SaveChanges();

            return(Ok());
        }
 public SpecificDataPage2ViewModel(string index, AppDatabase database)
 {
     user              = new User();
     this.index        = index;
     SaveSpecificData2 = new Command(ExecuteSaveSpecificData2);
     userRepo          = new UserRepo(database);
 }
Esempio n. 24
0
        private static void Upload_InsertData(AppDatabase db, SportEventViewModel[] eventViewModels)
        {
            EventSportViewModel[] sportVms = eventViewModels.Select(x => x.Sport).DistinctBy(x => x.Id).ToArray();
            var newSportIds = new Dictionary <ulong, long>();

            foreach (EventSportViewModel sportVm in sportVms)
            {
                Sport model = Map.ToModel(sportVm);
                long  dbId  = db.Sports.Add(model).Entity.Id;
                newSportIds.Add(sportVm.Id, dbId);
            }

            EventLeagueViewModel[] leagueVms = eventViewModels.Select(x => x.League).DistinctBy(x => x.Id).ToArray();
            var newLeagueIds = new Dictionary <ulong, long>();

            foreach (EventLeagueViewModel leagueVm in leagueVms)
            {
                League model = Map.ToModel(leagueVm);
                model.SportId = newSportIds[leagueVm.SportId];
                long dbId = db.Leagues.Add(model).Entity.Id;
                newLeagueIds.Add(leagueVm.Id, dbId);
            }

            foreach (SportEventViewModel eventVm in eventViewModels)
            {
                SportEvent model = Map.ToModel(eventVm);
                model.LeagueId = newLeagueIds[eventVm.League.Id];
                model.SportId  = newSportIds[eventVm.Sport.Id];
                db.Events.Add(model);
            }
        }
Esempio n. 25
0
 private static void PatientBillParameter(SqlCommand cmd, Guid guid, Guid patientGuid, DateTime patientBillDate, string otherPatientName)
 {
     AppDatabase.AddInParameter(cmd, PatientBill.Columns.BillGuid, SqlDbType.UniqueIdentifier, guid);
     AppDatabase.AddInParameter(cmd, PatientBill.Columns.PatientGuid, SqlDbType.UniqueIdentifier, AppShared.ToDbValueNullable(patientGuid));
     AppDatabase.AddInParameter(cmd, PatientBill.Columns.BillDate, SqlDbType.DateTime, patientBillDate);
     AppDatabase.AddInParameter(cmd, PatientBill.Columns.BillOther, SqlDbType.NVarChar, otherPatientName);
 }
 private static void OPDTreatmentProcedureParameters(SqlCommand cmd, Guid OPDTreatmentProcedureGuid, Guid OPDTreatmentProcedurePatientGuid, DateTime OPDTreatmentDate, Guid ModifiedBy)
 {
     AppDatabase.AddInParameter(cmd, OPDTreatmentProcedure.Columns.OPDTreatmentProcedureGuid, SqlDbType.UniqueIdentifier, OPDTreatmentProcedureGuid);
     AppDatabase.AddInParameter(cmd, OPDTreatmentProcedure.Columns.OPDTreatmentProcedurePatientGuid, SqlDbType.UniqueIdentifier, OPDTreatmentProcedurePatientGuid);
     AppDatabase.AddInParameter(cmd, OPDTreatmentProcedure.Columns.OPDTreatmentDate, SqlDbType.DateTime, OPDTreatmentDate);
     AppDatabase.AddInParameter(cmd, OPDTreatmentProcedure.Columns.OPDTreatmentModifiedBy, SqlDbType.UniqueIdentifier, ModifiedBy);
 }
Esempio n. 27
0
        /// <summary>
        /// Callback for when the Add Bedding button is clicked.
        /// </summary>
        /// <param name="sender">Object that triggered the event.</param>
        /// <param name="e">Arguments for the click event.</param>
        private async void AddBeddingButton_Clicked(object sender,
                                                    EventArgs e)
        {
            // Check if the maximum number of entries for the day is
            // already reached
            if (this.entries.Count >= MAX_ENTRIES_PER_DAY)
            {
                ToastController.ShortToast("Cannot add any more records for the day!");
                return;
            }

            // Create a new record book entry and insert it into the
            // database to obtain a unique Id
            BeddingRecordEntry entry = new BeddingRecordEntry()
            {
                HorseId = HorseManager.GetInstance().ActiveHorse.Id,
                Date    = date
            };
            await AppDatabase.GetInstance().Save <BeddingRecordEntry>(entry);

            // Add a new record view to the stack
            this.entries.Add(entry);
            BeddingRecordView view = new BeddingRecordView(entry);

            this.BeddingRecordStack.Children.Add(view);
        }
 private static void IPDPatientTreatmentParameters(SqlCommand cmd, Guid guid, Guid patientGuid, Guid treatmentGuid, Guid modifiedBy)
 {
     //AppDatabase.AddInParameter(cmd, IPDPatientTreatment.Columns.IPDPatientTreatmentGuid, SqlDbType.UniqueIdentifier, guid);
     AppDatabase.AddInParameter(cmd, IPDPatientTreatment.Columns.IPDPatientTreatmentPatientGuid, SqlDbType.UniqueIdentifier, patientGuid);
     AppDatabase.AddInParameter(cmd, IPDPatientTreatment.Columns.IPDPatientTreatmentTreatmentGuid, SqlDbType.UniqueIdentifier, treatmentGuid);
     AppDatabase.AddInParameter(cmd, IPDPatientTreatment.Columns.IPDPatientTreatmentModifiedBy, SqlDbType.UniqueIdentifier, modifiedBy);
 }
Esempio n. 29
0
        public ActionResult RoleEdit(string EntryKey, string Func)
        {
            AppraisalApproverModel appraisalApproverModel = new AppraisalApproverModel();

            if (String.IsNullOrEmpty(EntryKey) || String.IsNullOrEmpty(Func))
            {
                TempData["ErrorMessage"] = "Error : Please access the page properly.";
            }
            else
            {
                if (Func.Equals("Edit"))
                {
                    appraisalApproverModel = LINQCalls.getRoleSetupEntry(EntryKey);
                }
                else
                {
                    string retVal = new AppDatabase().deleteRoleSetup(EntryKey, "AppraisalDbConnectionString");
                    if (!String.IsNullOrEmpty(retVal) && !retVal.Split('|')[0].Equals("0"))
                    {
                        TempData["ErrorMessage"] = "Error : " + retVal.Split('|')[1];
                    }
                    else
                    {
                        return(RedirectToAction("ViewHRUsers"));
                    }
                }
            }
            TempData["appraisalApproverModel"] = appraisalApproverModel;
            return(RedirectToAction("HRRoleSetup"));
        }
 private static void AssociateComplainParameter(SqlCommand cmd, Guid AssociateComplainGuid, string AssociateComplainName, string AssociateComplainDescription, Guid modifiedBy)
 {
     AppDatabase.AddInParameter(cmd, AssociateComplain.Columns.AssociateComplainGuid, SqlDbType.UniqueIdentifier, AssociateComplainGuid);
     AppDatabase.AddInParameter(cmd, AssociateComplain.Columns.AssociateComplainName, SqlDbType.NVarChar, AppShared.SafeString(AssociateComplainName));
     AppDatabase.AddInParameter(cmd, AssociateComplain.Columns.AssociateComplainDescription, SqlDbType.NVarChar, AppShared.ToDbValueNullable(AssociateComplainDescription));
     AppDatabase.AddInParameter(cmd, AssociateComplain.Columns.AssociateComplainModifiedBy, SqlDbType.UniqueIdentifier, modifiedBy);
 }