public void InsertManagerShipmentTypesEdit(ShipmentTypesEditViewModel model) { var item = Mapper.Map <Shipment_Types>(model); m_ConentContext.Shipment_Types.Add(item); m_ConentContext.SaveChanges(); }
public void InsertManagerLangBook(Areas.Admin.Models.LangBooksEditViewModel model) { var item = Mapper.Map <Lang_Books>(model); m_contentContext.Lang_Books.Add(item); m_contentContext.SaveChanges(); }
public void InsertManagerHtmlBlocks(Areas.Admin.Models.HtmlBlocksEditViewModel model) { var item = Mapper.Map <HtmlBlocks>(model); m_contentContext.HtmlBlocks.Add(item); m_contentContext.SaveChanges(); }
public void SaveManagerSlider(Areas.Admin.Models.SliderEditViewModel model) { var item = Mapper.Map <Slider>(model); m_contentContext.Slider.Add(item); m_contentContext.SaveChanges(); }
public void InsertManagerProductTaxEdit(ProductTaxEditViewModel model) { var item = Mapper.Map <Tax_Products>(model); m_ContentContext.Tax_Products.Add(item); m_ContentContext.SaveChanges(); }
public void AddPost(string post) { var content = new Content { Post = post, }; contentContext.Contents.Add(content); contentContext.SaveChanges(); }
public void UpdateOrderStatus(int id, short status) { var query = from o in m_ContentContext.Order_Heads where o.Id == id select o; var item = query.FirstOrDefault(); item.Status = status; m_ContentContext.SaveChanges(); }
public int AddContent(Content content) { if (content == null) { throw new Exception("AddContent method error: content is null"); } _db.Contents.Add(content); _db.SaveChanges(); return(content.Id); }
public void InsertManagerPages(PagesEditViewModel model) { var item = Mapper.Map <Pages>(model); var qryNr = m_contentContext.Pages.Select(s => (int?)s.Id).Max(m => m); item.Id = (qryNr ?? 0) + 1; m_contentContext.Pages.Add(item); m_contentContext.SaveChanges(); }
public bool AddView(ViewEntity addView) { using (var context = new ContentContext()) { context.ViewEntity.Add(addView); return(context.SaveChanges() > 0); } }
public void Create(T obj) { try { if (obj == null) { throw new Exception("Cannot insert null object"); } Entities.Add(obj); _context.SaveChanges(); } catch (Exception ex) { throw ex; } }
public void Subscribe(User follower, User followee) { ContentContext.DbSet <Subscription>().Add(new Subscription { Follower = follower, Followee = followee }); ContentContext.SaveChanges(); }
public IActionResult CreateNewsAPI([FromBody] News news) { if (!ModelState.IsValid) { return(BadRequest()); } //TODO controllare news News checkNews = NewNews(news); if (checkNews == null) { return(BadRequest()); } _context.SaveChanges(); return(Ok(checkNews)); }
public bool UpdateView(ViewEntity updateView) { using (var context = new ContentContext()) { context.ViewEntity.Attach(updateView); context.Entry(updateView).State = EntityState.Modified; return(context.SaveChanges() > 0); } }
public void UpdateManagerCustomerEntityEdit(CustomerEntityEditViewModel model) { var query = from e in m_ContentContext.Customer_Entities where e.Id == model.Id select e; var item = query.FirstOrDefault(); item.BirthDate = model.BirthDate; item.Title = model.Caption; item.Company = model.Company; item.ContactPhone = model.ContactPhone; item.CustomerType = model.CustomerType; item.Gender = model.Gender; item.GroupId = model.GroupId; item.Status = model.Status; item.TaxNr = model.TaxNr; item.TaxOffice = model.TaxOffice; m_ContentContext.SaveChanges(); }
public void UpdatePosSettings(PosSettingsDetailViewModel model) { var query = from p in m_contentContext.Pos_Settings where p.Id == model.Id select p; var item = query.FirstOrDefault(); Mapper.Map(model, item); m_contentContext.SaveChanges(); }
public void Update(int id, string value) { var query = from p in m_contentContext.Params where p.Id == id select p; var item = query.FirstOrDefault(); item.Value = value; m_contentContext.SaveChanges(); }
public void CreateMessage(User user, string text, IDateTimeHelper dateTime) { ContentContext.DbSet <Message>().Add(new Message { Text = text, CreatedBy = user, CreatedDate = dateTime.CurrentDateTime }); ContentContext.SaveChanges(); }
public User CreateUser(string name) { var user = new User { Name = name }; ContentContext.DbSet <User>().Add(user); ContentContext.SaveChanges(); return(user); }
public async Task Add(ZabotaSlider model) { var path = _uploadPath.GetPath(); await _appDBContext.Sliders .AddAsync(new Entities.Slider { Image = "~/" + path.BaseImagePath + "/" + path.Slider + "/" + model.Image }); _appDBContext.SaveChanges(); }
//-------------------------------------- //-------------------------------------- public ContentTransfer NodeCreate(ContentTransfer nodeNew) { Node nodeDb = ContentXferToDbNode(nodeNew); using (ContentContext db = new ContentContext()) { db.Nodes.Add(nodeDb); db.SaveChanges(); } return NodeGetByPath(nodeNew.Path); }
public void InsertManagerPaymentTypesEdit(PaymentTypesEditViewModel model) { var item = Mapper.Map <Payment_Types>(model); m_ContentContext.Payment_Types.Add(item); m_ContentContext.SaveChanges(); foreach (var modelInst in model.PaymentInstallments) { var itemInst = Mapper.Map <Payment_Installment>(modelInst); itemInst.PaymentId = item.Id; m_ContentContext.Payment_Installment.Add(itemInst); } m_ContentContext.SaveChanges(); }
//Creates a tag in the context so it adds a new tag and then saves the changes in the context database. public ActionResult CreateTag(Tag taggy) { try { _context.Tags.Add(taggy); _context.SaveChanges(); return(RedirectToAction(nameof(Index))); } catch { return(View()); } }
private ItemRepository GetInMemoryCategoryRepository(List <Item> items) { DbContextOptions <ContentContext> options; var builder = new DbContextOptionsBuilder <ContentContext>(); builder.UseInMemoryDatabase("testDb"); options = builder.Options; ContentContext contentContext = new ContentContext(options); contentContext.Database.EnsureDeleted(); contentContext.Database.EnsureCreated(); contentContext.Items.AddRange(items); contentContext.SaveChanges(); return(new ItemRepository(contentContext, mapper.Object)); }
//Questo vale sia per le news che per le pratiche @Gianluca (Entrambe sono content) private static void AddContentTestData(ContentContext context) { News news1 = new News((Consultant)users[1], "Titolo news 1", "Lorem ipsum....."); News news2 = new News((Consultant)users[1], "Titolo news 2", "Lorem ipsum....", "http://attachedURL.com/"); news2.Publish(); context.Contents.Add(news1); context.Contents.Add(news2); Practice practice1 = new Practice((Consultant)users[1], "Titolo practica 1", "Lorem ipsum...", true); Practice practice2 = new Practice((Consultant)users[1], "Titolo practica 2", "Lorem ipsum...", false); context.Contents.Add(practice1); context.Contents.Add(practice1); context.SaveChanges(); }
public void DatabaseTest() { //Given using (var context = new ContentContext()) { // context.Database.EnsureDeleted(); context.Database.EnsureCreated(); var avatar = new AvatarEntity(); context.AvatarEntity.Add(avatar); Debug.WriteLine($"Before save: {avatar.Id}"); context.SaveChanges(); Debug.WriteLine($"After save: {avatar.Id}"); Assert.NotEqual(0, avatar.Id); } //When // var cards = this.ctxr.GetAllCards(); // //Then // Assert.Equal(3, cards.Count()); }
public bool AddOrRemoveFlag(FlagEntity flag, int userId = 0) { if (userId == 0) { using (var context = new ContentContext()) { context.Add(flag); return(context.SaveChanges() > 0); } // _ctx.Add(flag); } if (userId > 0) { using (var context = new ContentContext()) { context.Remove(flag); return(context.SaveChanges() > 0); } // _ctx.Remove(flag); } return(Save()); }
public bool AddOrRemoveVote(VoteEntity vote, int guestId = 0) { if (guestId > 0) { using (var context = new ContentContext()) { context.Remove(vote); return(context.SaveChanges() > 0); } //_ctx.Remove<VoteEntity>(Upvote); } if (guestId == 0) { using (var context = new ContentContext()) { context.Add(vote); return(context.SaveChanges() > 0); } //_ctx.Add<VoteEntity>(Upvote); } return(Save()); }
public void AddNewPost(Content content) { contentContext.Contents.Add(content); contentContext.SaveChanges(); }
public bool Save() => _ctx.SaveChanges() > 0;