public ActionResult <Category> PostCategory(CategoryPost category) { var t = _mapper.Map <Category>(category); ChronosDb.Categories.Add(t); return(Ok(t)); }
public async Task <IActionResult> Create([Bind("Id,BlogCategoryId,Title,Abstract,PostBody,IsReady")] CategoryPost categoryPost, IFormFile formFile) { if (ModelState.IsValid) { categoryPost.Created = DateTime.Now; categoryPost.ContentType = _imageService.RecordContentType(formFile); categoryPost.ImageData = await _imageService.EncodeFileAsync(formFile); //using slugs var slug = _slugService.URLFriendly(categoryPost.Title); if (_slugService.Isunique(_context, slug)) { categoryPost.Slug = slug; } else { ModelState.AddModelError("Title", "This Title has a duplicate slug!"); ViewData["BlogCategoryId"] = new SelectList(_context.BlogCategory, "Id", "Name"); return(View(categoryPost)); } _context.Add(categoryPost); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } ViewData["BlogCategoryId"] = new SelectList(_context.BlogCategory, "Id", "Name", categoryPost.BlogCategoryId); return(View(categoryPost)); }
public async Task <IActionResult> Edit(long id, [Bind("Id,CategoryName,Status")] CategoryPost categoryPost) { if (id != categoryPost.Id) { return(NotFound()); } if (ModelState.IsValid) { try { CategoryPost category = _context.CategoryPosts.Find(categoryPost.Id); category.CategoryName = categoryPost.CategoryName; category.MetaTitle = XuLyChuoi.GetMetaTitle(categoryPost.CategoryName); category.ModifiedDate = DateTime.Now; _context.Update(category); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!CategoryPostExists(categoryPost.Id)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(categoryPost)); }
public void UpdateCategory() { m_UIControl.lbl_CategoryError.Text = string.Empty; if (!Validate()) { MessageBox.Show("Name cannot be empty!"); return; } var category = DataService.GetCategoryDataController().GetByName(m_UIControl.tb_categoryName.Text); if (category != null) { m_UIControl.lbl_CategoryError.Text = "Category with same name already exists!"; return; } CategoryPost categoryPost = new CategoryPost(); categoryPost.ID = int.Parse(m_UIControl.tb_ID.Text); categoryPost.Name = m_UIControl.tb_categoryName.Text; categoryPost.Description = m_UIControl.tb_categoryDescription.Text; m_Category = DataService.GetCategoryDataController().Put(categoryPost); string message = (m_Category == null) ? "Failed to Update Category Details!" : "Category Details updated successfully!"; MessageBox.Show(m_UIControl, message); // fire category update event Event_EntryUpdated e = new Event_EntryUpdated(DBEntityType.CATEGORY, m_Category.ID); EventBroadcaster.Get().BroadcastEvent(e); m_UIControl.Close(); }
public async Task CreateCategoryAsync(CategoryPost category) { var userId = GetUserId(); if (category == null) { throw new ValidationErrorException("Category must be specified."); } Validator.CheckIsValid(category); var utcNow = Time.UtcNow; await RethrowUniqueKeyExceptionAsync( "UK_Category", () => new ValidationErrorException("Category with '{0}' name already exists.", category.Name), async() => { using (var persistence = Container.Get <IPersistenceService>()) { var dbCategory = new Category { Name = category.Name, Type = category.Type, UserId = userId, CreateDate = utcNow, ChangeDate = utcNow }; persistence.GetEntitySet <Category>().Add(dbCategory); await persistence.SaveChangesAsync(); } }); }
public IHttpActionResult PutCategoryPost(int id, CategoryPost categoryPost) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != categoryPost.id) { return(BadRequest()); } db.Entry(categoryPost).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!CategoryPostExists(id)) { return(NotFound()); } else { throw; } } return(StatusCode(HttpStatusCode.NoContent)); }
public ActionResult DeleteConfirmed(string id) { CategoryPost categoryPost = db.CategoryPosts.Find(id); db.CategoryPosts.Remove(categoryPost); db.SaveChanges(); return(RedirectToAction("Index")); }
public ActionResult Edit([Bind(Include = "CategoryPostId,CategoryName")] CategoryPost categoryPost) { if (ModelState.IsValid) { db.Entry(categoryPost).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(categoryPost)); }
// // POST: /PatentModel/Create public void CreateUpdates(string message, string link, int type, int id, string category) { string myname = Membership.GetUser().UserName; UserProfile userprofile = db.UserProfiles.SingleOrDefault(p => p.UserProfileId == id); UserProfile myprofile = db.UserProfiles.SingleOrDefault(p => p.UserName == myname); Update record = new Update { Time = DateTime.Now, message = message, link = link, New = true, Own = true, type = type, owner = myprofile.UserProfileId }; userprofile.Updates.Add(record); //add own update record if (category != null) { CategoryPost post = new CategoryPost { TimeStamp = DateTime.Now, PostMessage = message, Link = link, Type = 5, Postedby = myprofile.UserProfileId, Category = category, }; userprofile.CategoryPosts.Add(post); } string name = userprofile.UserName; IQueryable <string> custQuery = from cust in db.Relationships where cust.personBName == name select cust.personAName; foreach (string personAname in custQuery) { Update record2 = new Update { Time = DateTime.Now, message = message, link = link, New = true, Own = false, type = type, owner = userprofile.UserProfileId }; UserProfile tempuserprofile = db.UserProfiles.SingleOrDefault(p => p.UserName == personAname); tempuserprofile.Updates.Add(record2); } //add a new update record for the followers }
public ActionResult Create([Bind(Include = "CategoryPostId,CategoryName")] CategoryPost categoryPost) { if (ModelState.IsValid) { db.CategoryPosts.Add(categoryPost); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(categoryPost)); }
public IHttpActionResult GetCategoryPost(int id) { CategoryPost categoryPost = db.CategoryPosts.Find(id); if (categoryPost == null) { return(NotFound()); } return(Ok(categoryPost)); }
public async Task <IActionResult> Edit(int id, [Bind("Id,BlogCategoryId,Title,Abstract,PostBody,IsProductionReady,Created,Slug")] CategoryPost categoryPost, IFormFile formFile) { if (id != categoryPost.Id) { return(NotFound()); } if (ModelState.IsValid) { try { if (formFile != null) { categoryPost.ContentType = _imageService.RecordContentType(formFile); categoryPost.ImageData = await _imageService.EncodeFileAsync(formFile); } var slug = _slugService.URLFriendly(categoryPost.Title); if (slug != categoryPost.Slug) { if (_slugService.IsUnique(_context, slug)) { categoryPost.Slug = slug; } else { ModelState.AddModelError("Title", "This Title cannot be used as it results in a duplicate Slug!"); ViewData["BlogCategoryId"] = new SelectList(_context.BlogCategory, "Id", "Name", categoryPost.BlogCategoryId); return(View(categoryPost)); } } categoryPost.Updated = DateTime.Now; _context.Update(categoryPost); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!CategoryPostExists(categoryPost.Id)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } ViewData["BlogCategoryId"] = new SelectList(_context.BlogCategory, "Id", "Name", categoryPost.BlogCategoryId); return(View(categoryPost)); }
public IHttpActionResult PostCategoryPost(CategoryPost categoryPost) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } db.CategoryPosts.Add(categoryPost); db.SaveChanges(); return(CreatedAtRoute("DefaultApi", new { id = categoryPost.id }, categoryPost)); }
public async Task <HttpResponseMessage> CreateCategoryAsync([FromBody] CategoryPost category) { return(await ExecuteAsync(async() => { var categoryService = Container.Get <ICategoryService>(); await categoryService.CreateCategoryAsync(category); return new Information { Message = "Category created." }; })); }
public async Task <IActionResult> Create([Bind("Id,CategoryName,Status")] CategoryPost categoryPost) { if (ModelState.IsValid) { categoryPost.MetaTitle = XuLyChuoi.GetMetaTitle(categoryPost.CategoryName); categoryPost.CreatedDate = DateTime.Now; _context.Add(categoryPost); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(categoryPost)); }
public CategoryGet Post(CategoryPost post) { var categoryDTO = new CategoryDTO(post); m_Context.Categories.Add(categoryDTO); m_Context.SaveChanges(); if (categoryDTO == null) { return(null); } return(new CategoryGet(m_Context, categoryDTO)); }
public IHttpActionResult DeleteCategoryPost(int id) { CategoryPost categoryPost = db.CategoryPosts.Find(id); if (categoryPost == null) { return(NotFound()); } db.CategoryPosts.Remove(categoryPost); db.SaveChanges(); return(Ok(categoryPost)); }
// GET: Identity/CategoryPostAdmin/Delete/5 public ActionResult Delete(string id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } CategoryPost categoryPost = db.CategoryPosts.Find(id); if (categoryPost == null) { return(HttpNotFound()); } return(View(categoryPost)); }
public Post AddPost(PostDto post) { var postMap = _mapper.Map <Post>(post); _postRepository.Add(postMap); _unitOfWork.Complete(); var categoryPost = new CategoryPost { CategoryId = post.CategoryId, PostId = postMap.Id }; _categoryPostrepository.Add(categoryPost); _unitOfWork.Complete(); return(GetPost(postMap.Id)); }
private void btn_saveCategory_Click(object sender, EventArgs eventArgs) { if (!ValidateUI()) { return; } lbl_CategoryError.Text = string.Empty; string name = tb_categoryName.Text.Trim(); string desc = tb_categoryDescription.Text.Trim(); var category = DataService.GetCategoryDataController().GetByName(name); if (category != null) { lbl_CategoryError.Text = "Category with same name already exists!"; return; } CategoryPost categoryPost = new CategoryPost(); categoryPost.Name = name; categoryPost.Description = desc; m_Category = DataService.GetCategoryDataController().Post(categoryPost); if (m_Category == null) { Assert.Do("Failed to add category!"); DialogResult = DialogResult.Cancel; return; } // broadcast new entry added event Event_NewEntryAdded e = new Event_NewEntryAdded(DBEntityType.CATEGORY, m_Category.ID); EventBroadcaster.Get().BroadcastEvent(e); MessageBox.Show("Category Added successfully!"); ResetAll(); if (!checkBox_AddAnotherCategory.Checked) { DialogResult = DialogResult.OK; Close(); } }
public void CreateUpdates(string message, string PostCategory, int id) { string myname = Membership.GetUser().UserName; UserProfile userprofile = db.UserProfiles.SingleOrDefault(p => p.UserProfileId == id); //UserProfile myprofile = db.UserProfiles.SingleOrDefault(p => p.UserName == myname); CategoryPost post = new CategoryPost { Type = 0, PostMessage = message, TimeStamp = DateTime.Now, Category = PostCategory, Postedby = id }; //userprofile.Updates.Add(record); //add own update record userprofile.CategoryPosts.Add(post); }
private static void AddDefaultCategory() { int numCategories = GetCategoryDataController().GetRecordCount(); if (numCategories > 0) { return; } // add the default category CategoryPost category = new CategoryPost(); category.Name = "Default"; category.Description = "This is assigned to the product if no category is selected!"; GetCategoryDataController().Post(category); }
public CategoryGet Put(CategoryPost post) { var categoryDTO = m_Context.GetCategory(post.ID); if (categoryDTO == null) { return(null); } categoryDTO.CopyFrom(post); m_Context.Entry(categoryDTO).State = EntityState.Modified; m_Context.SaveChanges(); return(new CategoryGet(m_Context, categoryDTO)); }
public void CreateUpdates(Course model, string category) { string name = Membership.GetUser().UserName; myprofile = db.UserProfiles.SingleOrDefault(p => p.UserName == name); string CreateMessage = "New Course Created titled '" + model.CourseName + "'"; int coursenumber = db.Courses.Count() + 1; if (category != null) { if (category.Contains(';')) { string[] Tagnames = category.Split(';'); CategoryPost post = new CategoryPost { TimeStamp = DateTime.Now, PostMessage = CreateMessage, Link = "/Course/Details/" + coursenumber, Type = 4, Postedby = myprofile.UserProfileId, Category = Tagnames[0], }; myprofile.CategoryPosts.Add(post); } } //For own updates Update record = new Update { Time = DateTime.Now, message = CreateMessage, link = "/Course/Details/" + coursenumber, New = true, Own = true, type = 6, owner = myprofile.UserProfileId }; myprofile.Updates.Add(record); //add own update record db.Entry(myprofile).State = EntityState.Modified; db.SaveChanges(); }
public void CreateUpdates(Group model, string category) { if (category != null) { string GroupOwner = Membership.GetUser().UserName; myprofile = followPeersDB.UserProfiles.SingleOrDefault(p => p.UserName == GroupOwner); CategoryPost post = new CategoryPost { TimeStamp = DateTime.Now, PostMessage = "New Group Has Recently Been Created titled" + model.Name, Link = "/Groups/Details/" + model.GroupId, Type = 2, Postedby = myprofile.UserProfileId, Category = category, }; myprofile.CategoryPosts.Add(post); } }
public void Execute(PostDto request) { _validator.ValidateAndThrow(request); var post = new Post { Text = request.Text, Title = request.Title, PictureId = request.PictureId, UserId = request.UserId }; _context.Posts.Add(post); _context.SaveChanges(); foreach (var c in request.Category) { var categories = new CategoryPost { PostId = post.Id, CategoryId = c.Id }; _context.CategoryPost.Add(categories); _context.SaveChanges(); } }
public void Update(CategoryPost categoryPost) { db.Entry(categoryPost).State = EntityState.Modified; db.SaveChanges(); }
public CategoryDTO(CategoryPost categoryPOST) { Name = categoryPOST.Name; Description = categoryPOST.Description; }
public void Add(CategoryPost categoryPost) { db.CategoryPosts.Add(categoryPost); db.SaveChanges(); }
public ActionResult AddEvent(Event model, string[] InvitesId) { if (model.EventName == null) { model.EventName = "default"; } if (model.EventDate == DateTime.MinValue) { model.EventDate = DateTime.Now; } if (model.EventTime == DateTime.MinValue) { model.EventTime = DateTime.Now; } if (model.EventDesc == null) { model.EventDesc = "default"; } /* * //Adding Tags * //To keep track of tags being added * List<Tag> AddedTags = new List<Tag>(); * * //Adding the Tag * if (model.EventDesc!= null) * { * string EventDescTags = model.EventDesc.ToString(); * //If written new tag * string[] Tags = EventDescTags.Split(' '); * foreach (string tagname in Tags) * { * string Trimtagname = tagname.Trim(); * Tag Item = followPeersDB.Tags.FirstOrDefault(p => p.TagName.ToLower() == Trimtagname.ToLower()); * if (Item != null) * { * if (AddedTags.Contains(Item) != true && !(Item.Events.Any(p => p.EventId == model.EventId))) * { * Item.TagLinkedItems += 1; * model.Tags.Add(Item); * Item.Events.Add(model); * AddedTags.Add(Item); * } * } * else //If (Item == null) * { * //Create a New Tag * Tag NewItem = new Tag(); * NewItem.TagName = Trimtagname; * NewItem.TagLinkedItems = 1; * followPeersDB.Tags.Add(NewItem); * model.Tags.Add(NewItem); * NewItem.Events.Add(model); * AddedTags.Add(NewItem); * } * } * } * //-----------End of Adding Tags*/ string name = Membership.GetUser().UserName; UserProfile user = db.UserProfiles.SingleOrDefault(p => p.UserName == name); //Adding event for User (Creator of Event) and Adding User to Event user.Events.Add(model); model.Invitees.Add(user); //Adding event for All invitees and all invitees to event if (InvitesId != null) { foreach (var InviteeId in InvitesId) { if (InviteeId != null && InviteeId != "") { int id = Convert.ToInt32(InviteeId); UserProfile invitee = db.UserProfiles.SingleOrDefault(p => p.UserProfileId == id); try { if (user.UserProfileId != id) { invitee.Events.Add(model); model.Invitees.Add(invitee); //For Notifications string makeMessage = user.FirstName + " invited you to an event : '" + model.EventName + "'"; int eventnumber = followPeersDB.Events.Count() + 1; Notification newnoti = new Notification { message = makeMessage, link = "/Event/EventDetail/" + eventnumber, New = true, }; invitee.Notifications.Add(newnoti); } } catch { } } } } //Add event to database db.Events.Add(model); db.Entry(user).State = EntityState.Modified; db.SaveChanges(); //Calculating Event Id to Create Notification int EventId = followPeersDB.Events.Count(); //If Event was created, we find it and create a notification CategoryPost post = new CategoryPost { TimeStamp = DateTime.Now, PostMessage = "Created a new Event titled " + model.EventName, Type = 3, Postedby = user.UserProfileId, Category = model.EventDesc, Link = "/Event/EventDetail/" + EventId, }; user.CategoryPosts.Add(post); db.Entry(user).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); }