public void SavePost(PostDto postDto) { var model = _dbContext.Posts.Add(new Post { LayoutId = postDto.LayoutId, UserId = 3, PostTitle = postDto.PostTitle, CreateDate = DateTime.Now, SubCategoryId = 1, PostDesc = postDto.PostDesc, PostPhoto = postDto.PostPhoto, MainPageId = postDto.MainPageId }); foreach (var item in postDto.postDetailDtos) { _dbContext.PostDetails.Add(new PostDetail { PostId = model.Entity.PostId, PostHtml = item.PostHtml, CreateDate = DateTime.Now }); } _dbContext.SaveChanges(); }
public void Edit(string id, Post updatedItem) { var post = db.Post.FirstOrDefault(p => p.Id == id); if (post == null) { throw new KeyNotFoundException("A post with the id of " + id + "does not exist in the data store."); } post.Title = updatedItem.Title; post.Content = updatedItem.Content; if (!updatedItem.Private && post.Private) { post.Published = DateTime.Now; } post.Private = updatedItem.Private; post.IsContest = updatedItem.IsContest; post.Tags = updatedItem.Tags; post.UrlImage = updatedItem.UrlImage; post.CategoryId = updatedItem.CategoryId; post.Updated = DateTime.Now; db.SaveChanges(); }
public IActionResult Add(Menu menu, int?id) { if (ModelState.IsValid) { using (var context = new CMSContext()) { if (id == null) { context.Menu.Add(menu); int result = context.SaveChanges(); TempData["result"] = result == 1 ? "Insert Successful" : "Failed"; if (result == 1) { return(RedirectToAction("add", new { id = menu.Id })); } } else { var menuResult = context.Menu.Where(x => x.Id == id).FirstOrDefault(); menuResult.Id = menu.Id; menuResult.Name = menu.Name; menuResult.Item = menu.Item; menuResult.Status = Convert.ToBoolean(menu.Status); int result = context.SaveChanges(); ModelState.Clear(); BindMenu(menu); TempData["result"] = result == 1 ? "Update Successful" : "Failed"; } } } ViewBag.Title = id == null ? "Add New Menu" : "Update Menu"; return(View(menu)); }
public IActionResult DeleteCourse(long CourseId) { try { var userId = this.help.GetCurrentUser(HttpContext); if (userId <= 0) { return(StatusCode(401, "الرجاء الـتأكد من أنك قمت بتسجيل الدخول")); } var Course = (from p in db.Courses where p.CourseId == CourseId && (p.Status == 1) select p).SingleOrDefault(); if (Course == null) { return(NotFound("خــطأ : المستخدم غير موجود")); } Course.Status = 9; Course.UpdatedBy = userId; Course.UpdatedOn = DateTime.Now; db.SaveChanges(); return(Ok("Course Deleted")); } catch (Exception e) { return(StatusCode(500, e.Message)); } }
public ActionResult Create([Bind(Include = "Cust_Id,Cust_Name,Cust_Contact,Cust_EmailAddress,Cust_Address")] Customer_tbl customer_tbl) { if (ModelState.IsValid) { if (db.Customer_tbl.Where(a => a.Cust_Name == customer_tbl.Cust_Name).Count() > 0) { TempData["message"] = "This name has been registered!"; return(View()); } else if (db.Customer_tbl.Where(a => a.Cust_EmailAddress == customer_tbl.Cust_EmailAddress).Count() > 0) { TempData["message"] = "This email address has been registered!"; return(View()); } else { db.Customer_tbl.Add(customer_tbl); db.SaveChanges(); TempData["message"] = "New Customer Registered!"; return(RedirectToAction("CustomerManagement")); } } return(View(customer_tbl)); }
public ActionResult Create([Bind(Include = "Id,Name,Password,Type,Contact,EmailAddress")] User_tbl user_tbl) { if (ModelState.IsValid) { if (db.User_tbl.Where(a => a.Name == user_tbl.Name).Count() > 0) { TempData["message"] = "This name has been registered!"; return(View()); } else if (db.User_tbl.Where(a => a.EmailAddress == user_tbl.EmailAddress).Count() > 0) { TempData["message"] = "This email address has been registered!"; return(View()); } else { user_tbl.Type = "Agent"; db.User_tbl.Add(user_tbl); db.SaveChanges(); TempData["message"] = "New Agent Registered!"; return(RedirectToAction("AgentManagement", "Agent")); } } return(View(user_tbl)); }
public ActionResult Edit([Bind(Include = "Id,Username,Password,Email,FirstName,LastName,About,Avatar,Location,Phone,RegisteredOn,IsAdmin")] User user) { if (ModelState.IsValid) { db.Entry(user).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction(user.Username, "User")); } return(View(user)); }
public ActionResult Create([Bind(Include = "EventCatID,Name,Outdoor,Family")] EventCategory eventCategory) { if (ModelState.IsValid) { db.EventCategories.Add(eventCategory); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(eventCategory)); }
public ActionResult Create([Bind(Include = "Id,Title,Content,Created,Published,UrlImage,CombinedTags")] Post post) { if (ModelState.IsValid) { db.Post.Add(post); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(post)); }
public ActionResult Create(ShopModel shopModel) { if (ModelState.IsValid) { db.Shop.Add(shopModel); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(shopModel)); }
public ActionResult Create([Bind(Include = "PageId,PageName,PagePosition,PageVisible,PageContent")] Page page) { if (ModelState.IsValid) { db.Pages.Add(page); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(page)); }
public ActionResult Create([Bind(Include = "SubjectId,SubjectName,SubjectPosition,SubjectVisible")] Subject subject) { if (ModelState.IsValid) { db.Subjects.Add(subject); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(subject)); }
public ActionResult Create([Bind(Include = "EventID,EventCatID,LocationID,Name,StartTime,EndTime,OrganiserID")] Event @event) { if (ModelState.IsValid) { db.Events.Add(@event); db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.EventCatID = new SelectList(db.EventCategories, "EventCatID", "Name", @event.EventCatID); ViewBag.LocationID = new SelectList(db.Locations, "LocationID", "Name", @event.LocationID); return(View(@event)); }
public ActionResult Register([Bind(Include = "Id,Username,Password,Email,FirstName,LastName,About,Avatar,Location,Phone")] User user) { user.Password = Crypto.SHA256(user.Password); user.RegisteredOn = DateTime.Now; user.IsAdmin = 0; if (db.Users.Where(u => u.Username.Equals(user.Username)).FirstOrDefault() != null) { ModelState.AddModelError("", "That username is taken!"); return(View()); } else if (db.Users.Where(u => u.Email.Equals(user.Email)).FirstOrDefault() != null) { ModelState.AddModelError("", "Email is in use!"); return(View()); } else if (db.Users.Where(u => u.Phone.Equals(user.Phone)).FirstOrDefault() != null) { ModelState.AddModelError("", "Phone is in use!"); return(View()); } if (ModelState.IsValid) { db.Users.Add(user); db.SaveChanges(); return(RedirectToAction("Login", "Account")); } return(View(user)); }
public void OnDelete(Field entity, CMSContext db, DbContextTransaction transaction) { var evilTwin = entity.LinkedField; db.Fields.Remove(evilTwin); db.SaveChanges(); }
public LayoutTest() { var options = new DbContextOptionsBuilder <CMSContext>() .UseInMemoryDatabase(databaseName: "fake_db") .Options; dbContext = new CMSContext(options); dbContext.Layouts.Add(new Layout { Name = "layout99", CreateDate = DateTime.Now }); dbContext.LayoutComponents.Add(new LayoutComponent { Size = "6", Name = "Sol Alt Resim", CreateTime = DateTime.Now, ComponentClass = "<div>abc</div>" }); dbContext.SaveChanges(); }
public void OnDelete(Field entity, CMSContext db, DbContextTransaction transaction) { var fileLinks = db.FileLinks.Where(dl => dl.FieldId == entity.Id); db.FileLinks.RemoveRange(fileLinks); db.SaveChanges(); }
public void RemoveUnusedFiles() { using (var ctx = new CMSContext()) { IQueryable <File> files = ctx.Files.Where(x => !ctx.ContentDatas.Where(c => c.JSON.Contains(x.FileUId)).Any() && !ctx.ContentHeads.Where(w => w.ThumbFilePath.Contains(x.FileUId)).Any()); ctx.Files.RemoveRange(files); ctx.SaveChanges(); } }
public PostTest() { var options = new DbContextOptionsBuilder <CMSContext>() .UseInMemoryDatabase(databaseName: "fake_db") .Options; dbContext = new CMSContext(options); dbContext.Posts.Add(new Post { LayoutId = 1, UserId = 3, PostTitle = "FENERBAHÇE", CreateDate = DateTime.Now, SubCategoryId = 1, PostDesc = "Fenerbahçe baskette dünya birincisi", PostPhoto = "", MainPageId = 3 }); dbContext.Posts.Add(new Post { LayoutId = 1, UserId = 3, PostTitle = "MALATYASPOR", CreateDate = DateTime.Now, SubCategoryId = 1, PostDesc = "Malatya ligde 3. sırada", PostPhoto = "", MainPageId = 3 }); dbContext.PostDetails.Add(new PostDetail { PostId = 1, PostHtml = "<html></html>", CreateDate = DateTime.Now }); dbContext.PostDetails.Add(new PostDetail { PostId = 2, PostHtml = "<html><body></body></html>", CreateDate = DateTime.Now }); dbContext.PostImages.Add(new PostImage { PostId = 1, Desc = "Açıklama", Image = "Resim" }); dbContext.SaveChanges(); }
public void OnDelete(Field entity, CMSContext db, DbContextTransaction transaction) { var dictionaryLinks = db.DictionaryLinks.Where(dl => dl.FieldId == entity.Id); db.DictionaryLinks.RemoveRange(dictionaryLinks); DbDictionaryCache.ClearForFields(new int[] { entity.Id }); db.SaveChanges(); }
public ActionResult Create([Bind(Include = "Id,ProjectName,ProjectDesc,ProjectImage")] Project project) { project.PostedOn = DateTime.Today; var username = (string)Session["Username"]; var user = db.Users.Where(u => u.Username.Equals(username)).FirstOrDefault(); Account account = new Account(); account.Projects = project; account.Users = user; if (ModelState.IsValid) { db.Accounts.Add(account); db.Projects.Add(project); db.SaveChanges(); return(RedirectToAction(user.Username, "User")); } return(View(project)); }
public void AddPage(int ParentId, string Name) { _dbContext.MainPages.Add(new MainPage { Name = Name, ParentId = ParentId, CreateDate = DateTime.Now } ); _dbContext.SaveChanges(); }
public ActionResult Create([Bind(Include = "Itm_Id,Cust_Id,Itm_Name,Itm_Description")] Item_tbl item_tbl) { if (ModelState.IsValid) { if (db.Item_tbl.Where(a => a.Itm_Name == item_tbl.Itm_Name && a.Cust_Id == item_tbl.Cust_Id).Count() > 0) { TempData["message"] = "The customer already have item with same name!"; ViewBag.custList = getCustomer(); return(View()); } else { db.Item_tbl.Add(item_tbl); db.SaveChanges(); TempData["message"] = "New item registered!"; return(RedirectToAction("ItemManagement")); } } return(View(item_tbl)); }
public bool DeleteModuleMenus(int moduleID) { using (CMSContext context = new CMSContext()) { List<ModulesInMenus> moduleMenus = context.ModulesInMenus.Where(moduleMenu => moduleMenu.ModuleID == moduleID).ToList(); foreach (var moduleMenu in moduleMenus) { context.ModulesInMenus.Remove(moduleMenu); } return context.SaveChanges() > 0; } }
public bool DeleteModuleRoles(int moduleID) { using (CMSContext context = new CMSContext()) { List<ModulesInRoles> ModuleRoles = context.ModulesInRoles.Where(moduleposition => moduleposition.ModuleID == moduleID).ToList(); foreach (var moduleposition in ModuleRoles) { context.ModulesInRoles.Remove(moduleposition); } return context.SaveChanges() > 0; } }
public ActionResult Create([Bind(Include = "Sch_Id,Departure_Location,Arrival_Location,Dept_DateTime,Arrvl_DateTime,Ship_Id,Available_Container")] Schedule_tbl schedule_tbl) { if (ModelState.IsValid) { if (checkSchedule(schedule_tbl) == true) { schedule_tbl.Available_Container = db.Ship_tbl.Find(schedule_tbl.Ship_Id).Container_Limit; db.Schedule_tbl.Add(schedule_tbl); db.SaveChanges(); TempData["message"] = "New Schedule Registered!"; return(RedirectToAction("ScheduleManagement", "Schedule")); } else { ViewBag.PortLocation = getLocation(); ViewBag.ShipList = getShips(); return(View()); } } return(View(schedule_tbl)); }
// PUT: api/Employments/5 public async Task <ViewEmployments> PutEmployments(int id, ViewEmployments employments) { //TODO:Correct this schedul put //var productsModelFromDb = factory.CreateEmploymentsModelFromDb(employments); var employmentsInDb = await db.Employments.Include(x => x.Schedules).SingleOrDefaultAsync(x => x.EmploymentId == id); db.Employments.Attach(employmentsInDb); factory.EmploymentPutMaker(employments, employmentsInDb); db.SaveChanges(); return(employments); }
public void Save(ComplaintModel _complaint) { Complaint complaint = new Complaint() { CreatedBy = _complaint.UserId, CreatedDate = DateTime.Now, Description = _complaint.Description, Department = _complaint.Department, Subject = _complaint.Subject }; _db.Complaint.Add(complaint); _db.SaveChanges(); }
public IEnumerable<ErrorInfo> SaveModuleType(ModuleType moduleType) { using(CMSContext context=new CMSContext()) { IEnumerable<ErrorInfo> errors=ValidationHelper.Validate(moduleType); if(errors.Any()==false) { if(moduleType.ModuleTypeID<=0) { context.ModuleTypes.Add(moduleType); } else { context.Entry(moduleType).State=EntityState.Modified; } context.SaveChanges(); } return errors; } }
public IEnumerable<ErrorInfo> SavePosition(Position position) { using(CMSContext context=new CMSContext()) { IEnumerable<ErrorInfo> errors=ValidationHelper.Validate(position); if(errors.Any()==false) { if(position.PositionID<=0) { context.Positions.Add(position); } else { context.Entry(position).State=EntityState.Modified; } context.SaveChanges(); } return errors; } }
public bool DeleteFile(string publicId) { if (_cloudinary != null) { var deleteParams = new DeletionParams(publicId); var result = _cloudinary.Destroy(deleteParams); if (result.Result == "ok") { var toRemove = _context.Medias.Find(publicId); _context.Medias.Remove(toRemove); return(_context.SaveChanges() > 0); } } return(false); }
public ActionResult Create([Bind(Include = "ID,FirstName,LastName,EmailAddress,Birthdate,NumberOfComputers")] Contact contact) { try { if (ModelState.IsValid) { db.Contacts.Add(contact); db.SaveChanges(); return(RedirectToAction("Index")); } } catch (DataException) { ModelState.AddModelError("", "Unable to save changes. Please correct entry errors before continuing. All fields are required."); } return(View(contact)); }
public UserTest() { var options = new DbContextOptionsBuilder <CMSContext>() .UseInMemoryDatabase(databaseName: "fake_db") .Options; dbContext = new CMSContext(options); var x = dbContext.Users.Add(new User { UserName = "******", Email = "*****@*****.**", Password = "******", Photo = "", RoleId = 1 }); dbContext.SaveChanges(); }
public void Edit(string existingTag, string newTag) { using (var db = new CMSContext()) { var posts = db.Post.Where(post => post.CombinedTags.Contains(existingTag)).ToList(); posts = posts.Where(pos => pos.Tags.Contains(existingTag, StringComparer.CurrentCultureIgnoreCase)). ToList(); if (!posts.Any()) { throw new KeyNotFoundException("The tag" + existingTag + " does not exist"); } foreach (var post in posts) { post.Tags.Remove(existingTag); post.Tags.Add(newTag); } db.SaveChanges(); } }
public void RemoveUnusedFiles() { using (var ctx = new CMSContext()) { IQueryable<File> files = ctx.Files.Where(x => !ctx.ContentDatas.Where(c => c.JSON.Contains(x.FileUId)).Any() && !ctx.ContentHeads.Where(w => w.ThumbFilePath.Contains(x.FileUId)).Any()); ctx.Files.RemoveRange(files); ctx.SaveChanges(); } }
public IEnumerable<ErrorInfo> SaveModuleRoles(List<ModulesInRoles> ModuleRoles) { using (CMSContext context = new CMSContext()) { List<ErrorInfo> errors = new List<ErrorInfo>(); foreach (var moduleposition in ModuleRoles) { errors.AddRange(ValidationHelper.Validate(moduleposition)); if (errors.Any() == false) context.ModulesInRoles.Add(moduleposition); } if (errors.Any() == false) context.SaveChanges(); return errors; } }