/// <summary> /// Create a new Catalogue object. /// </summary> /// <param name="catalogueId">Initial value of the CatalogueId property.</param> /// <param name="catalogueCategoryName">Initial value of the CatalogueCategoryName property.</param> /// <param name="creationBy">Initial value of the CreationBy property.</param> /// <param name="creationDate">Initial value of the CreationDate property.</param> /// <param name="isDeleted">Initial value of the IsDeleted property.</param> public static Catalogue CreateCatalogue(global::System.Guid catalogueId, global::System.String catalogueCategoryName, global::System.String creationBy, global::System.DateTime creationDate, global::System.Boolean isDeleted) { Catalogue catalogue = new Catalogue(); catalogue.CatalogueId = catalogueId; catalogue.CatalogueCategoryName = catalogueCategoryName; catalogue.CreationBy = creationBy; catalogue.CreationDate = creationDate; catalogue.IsDeleted = isDeleted; return catalogue; }
/// <summary> /// Deprecated Method for adding a new object to the Catalogues EntitySet. Consider using the .Add method of the associated ObjectSet<T> property instead. /// </summary> public void AddToCatalogues(Catalogue catalogue) { base.AddObject("Catalogues", catalogue); }
/// <summary> /// Save a new catalogue in the database /// </summary> /// <param name="model">Catalogue model</param> /// <param name="userName">Name of logged user</param> public static CatalogueModel SaveCategoryCatalogue(CatalogueModel model, string userName) { bool categoryExist = false; using (VestalisEntities context = new VestalisEntities()) { categoryExist = context.Catalogues .Any(data => data.IsDeleted == false && data.BusinessApplicationId == model.BusinessApplicationId && data.CatalogueCategoryName == model.CatalogueCategoryName); //if the entity don't have a catalogue id, the system will perform insert operation //otherwise, the system will perform edit operation if (model.CatalogueId == Guid.Empty) { if (!categoryExist) { Catalogue catalogue = new Catalogue { BusinessApplicationId = model.BusinessApplicationId, CatalogueCategoryName = model.CatalogueCategoryName, }; //set auditory fields catalogue.CreationBy = userName; catalogue.CreationDate = DateTime.UtcNow; context.Catalogues.AddObject(catalogue); //save changes context.SaveChanges(); model.CatalogueId = catalogue.CatalogueId; } else { model.Errors.Add(LanguageResource.CatalogueCategoryExists); } } else { UpdateCatalogueCategory(model, userName, categoryExist, context); } } return model; }