private async Task RunScheduledAsync(Schedule schedule)
        {
            var currentTime = DateTime.UtcNow;

            if (schedule.NextRunUtc > currentTime)
            {
                return;
            }

            var frequency = (Frequency)Enum.Parse(typeof(Frequency), schedule.Frequency);

            var nextRun = GetNextRun(frequency, schedule.NextRunUtc);

            if (frequency == Frequency.Single)
            {
                schedule.Disabled = true;
            }
            else
            {
                //Handle scenarios where past executions may have been skipped.
                while (nextRun < currentTime)
                {
                    nextRun = GetNextRun(frequency, nextRun);
                }
            }

            schedule.NextRunUtc = nextRun;
            _database.Update(schedule);

            await RunAsync(0, schedule);
        }
        public void EditOperation(LatchOperation operation, IEnumerable <int> userIdsToAdd, IEnumerable <int> userIdsToRemove, IEnumerable <int> nodeIdsToAdd, IEnumerable <int> nodeIdsToRemove)
        {
            using (var scope = db.GetTransaction())
            {
                db.Update(operation);

                if (userIdsToAdd.Any())
                {
                    InsertLatchOperationUsers(userIdsToAdd.ToList(), operation.Id);
                }

                if (userIdsToRemove.Any())
                {
                    DeleteLatchOperationUsers(userIdsToRemove, operation.Id);
                }

                if (nodeIdsToAdd.Any())
                {
                    InsertLatchOperationNodes(nodeIdsToAdd.ToList(), operation.Id);
                }

                if (nodeIdsToRemove.Any())
                {
                    DeleteLatchOperationNodes(nodeIdsToRemove, operation.Id);
                }

                scope.Complete();
            }
        }
Beispiel #3
0
        public IHttpActionResult UpdateCategoryModel(long id, CategoryModel categoryModel)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != categoryModel.CategoryId)
            {
                return(BadRequest());
            }

            //db.Entry(categoryModel).State = EntityState.Modified;


            try
            {
                db.Update(categoryModel);
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!CategoryModelExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
Beispiel #4
0
 private void CreateAndSaveMediaXml(XElement xml, int id, UmbracoDatabase db)
 {
     var poco = new ContentXmlDto {
         NodeId = id, Xml = xml.ToString(SaveOptions.None)
     };
     var exists = db.FirstOrDefault <ContentXmlDto>("WHERE nodeId = @Id", new { Id = id }) != null;
     int result = exists ? db.Update(poco) : Convert.ToInt32(db.Insert(poco));
 }
Beispiel #5
0
        public void FlagMigrationAsFinished(IUmbracoMigration migration)
        {
            var migrationName = migration.GetType().Name;

            var migrationHistory = UmbracoDatabase.Single <MigrationHistory>("WHERE Name = @Name", new { Name = migrationName });

            migrationHistory.Completed = true;
            UmbracoDatabase.Update(migrationHistory);
        }
Beispiel #6
0
 public bool Update(TEntityType entity)
 {
     if (entity.Id == default)
     {
         return(false);
     }
     entity.UpdatedOn = DateTime.UtcNow;
     return(_database.Update(entity) > 0);
 }
        public async Task <ActionResult> Edit(PropertyViewModel propertyModel)
        {
            //Edit([Bind(Include = "PropertyId,PropertyTitle,ReferenceNo,PropertyCategory,PropertyType,MainFeature,Location,TotalSize,BuildUpArea,ReraPermitNo,SellPrice,carparking,bedrooms,baths,AvailabilityStatus,DevelopmentStatus,ServiceType,PropertyDetailPageURL,PropertyImagePath,PropertyOwnerId")] PropertyModel propertyModel)
            if (ModelState.IsValid)
            {
                await Task.FromResult(db.Update(propertyModel));

                return(RedirectToCurrentUmbracoPage());
            }
            return(PartialView(StringConstants.PARTIAL_VIEW_PATH + PARTIAL_VIEW_EDIT, await Task.FromResult(propertyModel)));
        }
Beispiel #8
0
 public void SaveOrUpdate(EasyADGroup group)
 {
     if (group.Id > 0)
     {
         _database.Update(group);
     }
     else
     {
         _database.Save(group);
     }
 }
        public ActionResult EditRecurringEvent(EditRecurringEventModel ere)
        {
            List <EventLocation> locations = this._db.Query <EventLocation>("SELECT * FROM ec_locations").ToList();

            locations.Insert(0, new EventLocation()
            {
                LocationName = "No Location", Id = 0
            });
            SelectList list = new SelectList(locations, "Id", "LocationName", ere.selectedLocation);

            ere.locations = list;

            if (!ModelState.IsValid)
            {
                TempData["StatusEditEvent"] = "Invalid";
                return(PartialView(ere));
            }

            TempData["StatusEditEvent"] = "Valid";

            RecurringEvent re = new RecurringEvent()
            {
                Id               = ere.id,
                title            = ere.title,
                allDay           = ere.allDay,
                calendarId       = ere.calendar,
                locationId       = ere.selectedLocation,
                description      = String.Empty,
                day              = (int)ere.day,
                frequency        = (int)ere.frequency,
                monthly_interval = (int)ere.monthly
            };

            _db.Update(re, re.Id);

            //Get Descriptions for Event
            Dictionary <string, EventDesciption> descriptions = this._db.Query <EventDesciption>("SELECT * FROM ec_eventdescriptions WHERE eventid = @0", ere.id).ToDictionary(x => x.CultureCode);
            List <ILanguage> languages = Services.LocalizationService.GetAllLanguages().ToList();

            foreach (var lang in languages)
            {
                if (!descriptions.ContainsKey(lang.CultureInfo.ToString()))
                {
                    descriptions.Add(lang.CultureInfo.ToString(), new EventDesciption()
                    {
                        CultureCode = lang.CultureInfo.ToString(), EventId = ere.id, Id = 0, Type = (int)EventType.Recurring, CalendarId = ere.calendar
                    });
                }
            }
            ere.Descriptions = descriptions;

            return(PartialView(ere));
        }
        public bool UpdateFavoriteContent(string propertyName, int userId, int?sortOrder = null)
        {
            var userProperties = GetAllPropertiesByUser(userId);

            if (userProperties.Any(x => x.PropertyName == propertyName))
            {
                try
                {
                    var favoriteProperties = userProperties.Where(x => !x.IsFavorite.HasValue || x.IsFavorite.Value);
                    var property           = userProperties.FirstOrDefault(x => x.PropertyName == propertyName);
                    var useCount           = property.UseCount + 1;

                    property.UseCount    = useCount;
                    property.LastUpdated = DateTime.UtcNow;

                    if (sortOrder.HasValue)
                    {
                        property.SortOrder = sortOrder.Value;
                    }
                    else if (property.IsFavorite.HasValue && !property.IsFavorite.Value)
                    {
                        property.SortOrder = favoriteProperties.Count();
                    }

                    db.Update(property);
                    return(true);
                }
                catch (Exception ex)
                {
                    LogHelper.Error <FavoriteContentRepository>("Unable to update property " + propertyName + " in the FavoriteContent database table.", ex);
                    return(false);
                }
            }
            else
            {
                return(AddFavoriteContent(propertyName, userId, null));
            }
        }
Beispiel #11
0
        public void Save(IReadOnlyList <MigrationRecord> records)
        {
            EnsureTable();
            foreach (var record in records)
            {
                TruncateLogIfRequired(record);

                var exists = _database.Exists <MigrationRecord>(record.Version);
                if (exists)
                {
                    _database.Update(record);
                }
                else
                {
                    _database.Insert(record);
                }
            }
        }
Beispiel #12
0
        public void CreateDatabaseSchema(DatabaseType dbType, bool?skipInstaller)
        {
            //Depending on DB Type - Change Provider
            if (dbType == DatabaseType.MySQL)
            {
                SqlSyntaxContext.SqlSyntaxProvider = new MySqlSyntaxProvider();
            }
            else if (dbType == DatabaseType.SQLCE)
            {
                SqlSyntaxContext.SqlSyntaxProvider = new SqlCeSyntaxProvider();

                //Create a path to an Umbraco.sdf file in App_Data
                var path = Path.Combine(umbracoSitePath, "App_Data", "Umbraco.sdf");

                //Modified Connection String for CE creation
                var modConnection = string.Format("Data Source={0};Flush Interval=1;", path);

                //Update connection string
                connectionString = modConnection;
            }
            else
            {
                SqlSyntaxContext.SqlSyntaxProvider = new SqlServerSyntaxProvider();
            }

            //Create a new Umbraco DB object using connection details
            var db = new UmbracoDatabase(connectionString, providerName);

            //Create DB Schema
            //Get the method we want to run
            var methodToRun = typeof(PetaPocoExtensions).GetMethod("CreateDatabaseSchema", BindingFlags.Static | BindingFlags.NonPublic);

            //Invoke the Method - CreateDatabaseSchema(db, false)
            methodToRun.Invoke(null, new object[] { db, false });


            //Only Add/Update default admin user of admin/admin
            if (skipInstaller == true)
            {
                //Add/update default admin user of admin/admin
                db.Update <UserDto>("set userPassword = @password where id = @id", new { password = "******", id = 0 });
            }
        }
Beispiel #13
0
        public System.Web.Http.IHttpActionResult UpdateSeason(Season season)
        {
            UmbracoDatabase db = ApplicationContext.DatabaseContext.Database;

            try
            {
                db.Update(new Season
                {
                    Season_Id         = season.Season_Id,
                    Season_Title      = season.Season_Title,
                    Season_Location   = season.Season_Location,
                    Season_Start_Date = season.Season_Start_Date,
                    Season_End_Date   = season.Season_End_Date
                });
            }
            catch (System.Exception exception)
            {
                return(Content(System.Net.HttpStatusCode.BadRequest, exception));
            }

            return(Ok());
        }
Beispiel #14
0
        public System.Web.Http.IHttpActionResult UpdateGame(Game game)
        {
            UmbracoDatabase db = ApplicationContext.DatabaseContext.Database;

            try
            {
                db.Update(new Game
                {
                    Game_Id       = game.Game_Id,
                    Season_Id     = game.Season_Id,
                    Game_Location = game.Game_Location,
                    Opposing_Team = game.Opposing_Team,
                    Game_Date     = game.Game_Date
                });
            }
            catch (System.Exception exception)
            {
                return(Content(System.Net.HttpStatusCode.BadRequest, exception));
            }

            return(Ok());
        }
Beispiel #15
0
        public void EditOrder(Order order)
        {
            var orderPoco = _orderMapper.MapToPoco(order);

            try
            {
                _db.BeginTransaction();

                _db.Execute("DELETE FROM OrderedMeals Where OrderId = @0", orderPoco.Id);
                foreach (var orderedMealPoco in orderPoco.OrderedMeals)
                {
                    orderedMealPoco.OrderId = orderPoco.Id;
                    _db.Insert("OrderedMeals", "Id", orderedMealPoco);
                }
                _db.Update("Orders", "Id", orderPoco);
                _db.CompleteTransaction();
            }
            catch (Exception)
            {
                _db.AbortTransaction();
                throw;
            }
        }
        public ActionResult EditRecurringEvent(EditRecurringEventModel ere)
        {
            List <EventLocation> locations = this._db.Query <EventLocation>("SELECT * FROM ec_locations").ToList();

            locations.Insert(0, new EventLocation()
            {
                LocationName = "No Location", Id = 0
            });
            SelectList list = new SelectList(locations, "Id", "LocationName", ere.selectedLocation);

            ere.locations = list;

            if (!ModelState.IsValid)
            {
                TempData["StatusEditEvent"] = "Invalid";
                return(PartialView(ere));
            }

            TempData["StatusEditEvent"] = "Valid";

            RecurringEvent re = new RecurringEvent()
            {
                Id               = ere.id,
                title            = ere.title,
                allDay           = ere.allDay,
                calendarId       = ere.calendar,
                locationId       = ere.selectedLocation,
                description      = ere.description,
                day              = (int)ere.day,
                frequency        = (int)ere.frequency,
                monthly_interval = (int)ere.monthly
            };

            _db.Update(re, re.Id);

            return(PartialView(ere));
        }
Beispiel #17
0
 public void Update(StructuralGroup group)
 {
     _db.Update(group);
 }
Beispiel #18
0
 public void EditRestaurant(Restaurant restaurant)
 {
     _db.Update("Restaurants", "Id", _mapper.MapToPoco(restaurant));
 }
Beispiel #19
0
 /// <summary>
 /// Persist changes to a usergroup
 /// </summary>
 /// <param name="poco">The group to update, of type <see cref="UserGroupPoco"/></param>
 public void UpdateUserGroup(UserGroupPoco poco)
 {
     _database.Update(poco);
 }
Beispiel #20
0
 public void Update(Product product)
 {
     db.Update("Products", "Id", product);
 }
 /// <summary>
 ///
 /// </summary>
 /// <param name="poco"></param>
 public void UpdateInstance(WorkflowInstancePoco poco)
 {
     _database.Update(poco);
 }
Beispiel #22
0
 public void Update <T>(T form) where T : CustomForm
 {
     _db.Update(form);
 }
Beispiel #23
0
 public void Update(ContactForm form)
 {
     _db.Update(form);
 }
Beispiel #24
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="poco"></param>
 public void UpdateTask(WorkflowTaskInstancePoco poco)
 {
     _database.Update(poco);
 }
Beispiel #25
0
 public void Delete(int orderId)
 {
     db.Update("Orders", "Id", new { IsDeleted = true }, orderId);
 }
Beispiel #26
0
 public void Update(Category category)
 {
     db.Update("Categories", "Id", category);
 }
 public virtual T Update(T dbEntity)
 {
     Database.Update(dbEntity);
     return(dbEntity);
 }
Beispiel #28
0
        /// <summary>
        /// Creates the Configuration table
        /// </summary>
        public override void Up()
        {
            //  Environment
            Alter.Table <Environment103>().AddColumn(nameof(Environment103.SortOrder)).AsInt32().NotNullable().WithDefaultValue(999999);
            Alter.Table <Environment103>().AddColumn(nameof(Environment103.Enable)).AsBoolean().NotNullable().WithDefaultValue(true);
            Alter.Table <Environment103>().AddColumn(nameof(Environment103.ContinueProcessing)).AsBoolean().NotNullable().WithDefaultValue(true);
            Alter.Table <Environment103>().AddColumn(nameof(Environment103.ColorIndicator)).AsString(7).NotNullable().WithDefaultValue("#df7f48");

            //  Journal
            Delete.ForeignKey("FK_" + nameof(Shield) + "_" + nameof(Journal) + "_" + nameof(Dto.Configuration)).OnTable <Journal101>();
            Create.Index("IX_" + nameof(Shield) + "_" + nameof(Journal103.Datestamp)).OnTable <Journal103>()
            .OnColumn(nameof(Journal103.Datestamp)).Ascending().WithOptions().NonClustered();

            //  Configuration
            Delete.Index("IX_" + nameof(Shield) + "_" + nameof(Configuration101.AppId)).OnTable <Configuration101>();
            Create.Index("IX_" + nameof(Shield) + "_" + nameof(Configuration103.AppId)).OnTable <Configuration103>()
            .OnColumn(nameof(Configuration103.AppId)).Ascending().WithOptions().NonClustered();

            //  Check if Backoffice Access has been installed, as we may
            //  need to update the configuration to match the new class
            var sql = new Sql();

            sql.Where <Configuration>(x => x.AppId == "BackofficeAccess");

            var config = _database.FirstOrDefault <Configuration>(sql);

            if (config == null)
            {
                return;
            }

            var definition = new
            {
                backendAccessUrl             = "",
                ipAddressesAccess            = 0,
                ipAddresses                  = new IpEntry103[0],
                unauthorisedAction           = TransferTypes.Redirect,
                unauthorisedUrlType          = UmbracoUrlTypes.Url,
                unauthorisedUrl              = "",
                unauthorisedUrlXPath         = "",
                unauthorisedUrlContentPicker = ""
            };

            //  Deserialize the current config to an anonymous object
            var oldData = JsonConvert.DeserializeAnonymousType(config.Value, definition);

            //  Copy the configuration to the new anonymous object
            var newData = new
            {
                oldData.backendAccessUrl,
                oldData.ipAddressesAccess,
                oldData.ipAddresses,
                oldData.unauthorisedAction,
                urlType = new UrlType103
                {
                    UrlSelector      = oldData.unauthorisedUrlType,
                    StrUrl           = oldData.unauthorisedUrl,
                    XPathUrl         = oldData.unauthorisedUrlXPath,
                    ContentPickerUrl = oldData.unauthorisedUrlContentPicker
                }
            };

            //  serialize the new configuration to the db entry's value
            config.Value = JsonConvert.SerializeObject(newData, Formatting.None);

            //  Update the entry within the DB.
            _database.Update(config);
        }