Esempio n. 1
0
 /// <summary>
 ///  Save each row from the uploaded file in the CompanyInventory db table
 /// </summary>
 /// <param name="item">The item to be saved in the CompanyInventory db table</param>
 public int SaveInventoryItem(CompanyInventory item)
 {
     try
     {
         db.Save(item);
     }
     catch (Exception ex)
     {
         return(-1);
     }
     return(item.Id);
 }
Esempio n. 2
0
 private static void ResetSettings(UmbracoDatabase db, List <GigyaUmbracoModuleSettings> settings, List <string> currentGlobalSettings)
 {
     // reset back to original values
     for (int i = 0; i < settings.Count; i++)
     {
         settings[i].GlobalParameters = currentGlobalSettings[i];
         db.Save(settings[i]);
     }
 }
Esempio n. 3
0
 public void SaveOrUpdate(EasyADGroup group)
 {
     if (group.Id > 0)
     {
         _database.Update(group);
     }
     else
     {
         _database.Save(group);
     }
 }
Esempio n. 4
0
        /// <summary>
        /// Inserts a new usergroup into the database
        /// </summary>
        /// <param name="name">The group name</param>
        /// <param name="alias">The group alias</param>
        /// <param name="deleted">The group state</param>
        /// <returns>The newly created user group, of type <see cref="UserGroupPoco"/></returns>
        public UserGroupPoco InsertUserGroup(string name, string alias, bool deleted)
        {
            var poco = new UserGroupPoco
            {
                Name    = name,
                Alias   = alias,
                Deleted = deleted
            };

            _database.Save(poco);
            return(poco);
        }
Esempio n. 5
0
        public IHttpActionResult PostCategoryModel(CategoryModel categoryModel)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            //db.CategoryModels.Add(categoryModel);
            //db.SaveChanges();
            db.Save(categoryModel);

            return(CreatedAtRoute("DefaultApi", new { id = categoryModel.CategoryId }, categoryModel));
        }
Esempio n. 6
0
        private async Task RunAsync(int userId, Schedule schedule)
        {
            var log = new Log
            {
                ExecutionDateTimeUtc = DateTime.UtcNow,
                ScheduleId           = schedule.Id,
                UserId      = userId,
                MachineName = Environment.MachineName
            };

            try {
                var url = schedule.Url;
                if (!url.StartsWith("http"))
                {
                    url = $"http://localhost{url}";
                }
                using (var client = new HttpClient())
                {
                    var req         = new HttpRequestMessage(new HttpMethod(schedule.HttpVerb), url);
                    var contentType = "application/json";
                    schedule.Headers?.ForEach(h => {
                        if (h.Key.Equals("Content-Type", StringComparison.InvariantCultureIgnoreCase))
                        {
                            contentType = h.Value;
                        }
                        else
                        {
                            req.Content.Headers.Add(h.Key, h.Value);
                        }
                    });

                    if (!string.IsNullOrWhiteSpace(schedule.Data))
                    {
                        req.Content = new StringContent(schedule.Data, Encoding.UTF8, contentType);
                    }
                    var resp = await client.SendAsync(req).ConfigureAwait(false);

                    log.Result = await resp.Content.ReadAsStringAsync().ConfigureAwait(false);

                    log.Success = resp.IsSuccessStatusCode;
                }
            }
            catch (Exception ex)
            {
                _log.Error($"Failed to run schedule {schedule.Name}", ex);
                log.Result = ex.Message;
            }

            _database.Save(log);
        }
        public static void CreateSubmission(string formAlias, Dictionary <string, string> submissionContent)
        {
            int formID = GetFormIDFromAlias(formAlias);

            if (formID > -1)
            {
                FormStorageSubmissionModel formStorageSubmission = new FormStorageSubmissionModel();
                formStorageSubmission.FormID   = formID;
                formStorageSubmission.IP       = GetUserIP();
                formStorageSubmission.Datetime = DateTime.Now;
                try
                {
                    DatabaseConnection.Save(formStorageSubmission);
                }
                catch (Exception ex)
                {
                    Log.Error("Unable to save to FormStorageSubmissions table : " + ex.Message);
                    return;
                }

                foreach (KeyValuePair <string, string> currentField in submissionContent)
                {
                    FormStorageEntryModel formStorageEntry = new FormStorageEntryModel();
                    formStorageEntry.SubmissionID = formStorageSubmission.SubmissionID;
                    formStorageEntry.FieldAlias   = currentField.Key;
                    formStorageEntry.Value        = !string.IsNullOrEmpty(currentField.Value) ? currentField.Value : string.Empty;
                    try
                    {
                        DatabaseConnection.Save(formStorageEntry);
                    }
                    catch (Exception ex)
                    {
                        Log.Error("Unable to save to FormStorageEntries table : " + ex.Message);
                    }
                }
            }
        }
Esempio n. 8
0
        private void AddEntityToChangedTable(EntityType type, string name)
        {
            var changedEntities         = _database.Fetch <ChauffeurChangesTable>("SELECT * FROM Chauffeur_Changes");
            var filteredChangedEntities = changedEntities.Where(c => c.EntityType == Convert.ToInt32(type) && c.Name == name).ToList();

            if (filteredChangedEntities.Count == 0)
            {
                _database.Save(new ChauffeurChangesTable
                {
                    EntityType = Convert.ToInt32(type),
                    Name       = name,
                    ChangeDate = DateTime.Now,
                    ChangeType = Convert.ToInt32(ChangeType.SAVED)
                });
            }
        }
Esempio n. 9
0
        public bool LogErrorinDb(Exception ex)
        {
            ApplicationErrorModel err = new ApplicationErrorModel();

            err.Message   = ex.InnerException.Message;
            err.OccuredOn = System.DateTime.Now;
            err.MachineID = "test";
            try
            {
                db.Save(err);
                return(true);
            }
            catch
            {
                return(false);
            }
        }
Esempio n. 10
0
        private void CreateFieldMappings(UmbracoDatabase db)
        {
            var sql      = "SELECT * FROM gigya_settings";
            var settings = db.Fetch <GigyaUmbracoModuleSettings>(sql);
            var currentGlobalSettings = settings.Select(i => i.GlobalParameters).ToList();

            // create field mappings if don't already exist
            foreach (var setting in settings)
            {
                var mappings = !string.IsNullOrEmpty(setting.MappingFields) ? JsonConvert.DeserializeObject <List <MappingField> >(setting.MappingFields) : new List <MappingField>();
                CreateFieldMapping(ref mappings, _umbracoFirstName, Gigya.Umbraco.Module.Constants.GigyaFields.FirstName);
                CreateFieldMapping(ref mappings, _umbracoLastName, Gigya.Umbraco.Module.Constants.GigyaFields.LastName);
                CreateFieldMapping(ref mappings, _umbracoAge, _gigyaAge);

                setting.MappingFields = JsonConvert.SerializeObject(mappings);
                db.Save(setting);
            }
        }
        /// <summary>
        /// Insert a new Auth Token into the custom DB table OR
        /// Update just the auth token if we find a record for the backoffice user already
        /// </summary>
        /// <param name="authToken"></param>
        public static void InsertAuthToken(UmbracoAuthToken authToken)
        {
            //Just to be 100% sure for data sanity that a record for the user does not exist already
            var existingRecord = GetAuthToken(authToken.IdentityId);

            //Insert new record if no item exists already
            if (existingRecord == null)
            {
                //Getting issues with insert & ID being 0 causing a conflict
                Database.Insert(authToken);
            }
            else
            {
                //Update the existing record
                existingRecord.AuthToken   = authToken.AuthToken;
                existingRecord.DateCreated = authToken.DateCreated;

                //Save the existing record we found
                Database.Save(existingRecord);
            }
        }
Esempio n. 12
0
        public override async Task <DeliverableResponse> Run(string command, string[] args)
        {
            var dbNotReady = false;

            try
            {
                if (!database.TableExist(TableName))
                {
                    if (!await SetupDatabase())
                    {
                        return(DeliverableResponse.FinishedWithError);
                    }
                }
            }
            catch (DbException)
            {
                Out.WriteLine("There was an error checking for the database Chauffeur Delivery tracking table, most likely your connection string is invalid or your database doesn't exist.");
                Out.WriteLine("Chauffeur will attempt to run the first delivery, expecting it to call `install`.");
                dbNotReady = true;
            }

            string directory;

            if (!settings.TryGetChauffeurDirectory(out directory))
            {
                await Out.WriteLineAsync("Error accessing the Chauffeur directory. Check your file system permissions");

                return(DeliverableResponse.Continue);
            }

            var allDeliveries = fileSystem.Directory
                                .GetFiles(directory, "*.delivery", SearchOption.TopDirectoryOnly)
                                .ToArray();

            if (!allDeliveries.Any())
            {
                await Out.WriteLineAsync("No deliveries found.");

                return(DeliverableResponse.Continue);
            }

            if (dbNotReady)
            {
                try
                {
                    var delivery = allDeliveries.First();
                    var file     = fileSystem.FileInfo.FromFileName(delivery);

                    var tracking = await Deliver(file);

                    if (!tracking.SignedFor)
                    {
                        return(DeliverableResponse.FinishedWithError);
                    }

                    if (!await SetupDatabase())
                    {
                        return(DeliverableResponse.FinishedWithError);
                    }

                    database.Save(tracking);

                    allDeliveries = allDeliveries.Skip(1).ToArray();
                }
                catch (DbException)
                {
                    Out.WriteLine("Ok, I tried. Chauffeur had a database error, either a missing connection string or the DB couldn't be setup.");
                    return(DeliverableResponse.FinishedWithError);
                }
            }

            await ProcessDeliveries(allDeliveries);

            return(DeliverableResponse.Continue);
        }
Esempio n. 13
0
        private static void SaveOrder(OrderData fetch, UmbracoDatabase db)
        {
            fetch.UpdateDate = DateTime.Now;

            db.Save(fetch);
        }