public IHttpActionResult PutBeskeder(int id, Beskeder beskeder) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != beskeder.BeskedId) { return(BadRequest()); } db.Entry(beskeder).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!BeskederExists(id)) { return(NotFound()); } else { throw; } } return(StatusCode(HttpStatusCode.NoContent)); }
public IHttpActionResult PutUgedage(int id, Ugedage ugedage) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != ugedage.UgedagId) { return(BadRequest()); } db.Entry(ugedage).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!UgedageExists(id)) { return(NotFound()); } else { throw; } } return(StatusCode(HttpStatusCode.NoContent)); }
public string InsertAddress(Address addres, int id, int addtype, int subid) { try { using (var db = new TableContext()) { var person = db.Rusers.Where(s => s.RegisteredUserID == id).FirstOrDefault(); var type = db.addresstypes.Find(addtype); addres.Addresstypes = type; var sub = db.surbubs.Find(subid); addres.sub = sub; addres.RegisteredUsers = person; db.addresses.Add(addres); db.SaveChanges(); person.AddressID = addres.AddressID; db.Entry(person).State = System.Data.Entity.EntityState.Modified; db.SaveChanges(); } return("address was added"); } catch (Exception ex) { return(ex.Message); } }
public ActionResult AddOrEdit(Teacher teacher) { try { if (teacher.ImageUpload != null) { string fileName = Path.GetFileNameWithoutExtension(teacher.ImageUpload.FileName); string extension = Path.GetExtension(teacher.ImageUpload.FileName); fileName = fileName + DateTime.Now.ToString("yymmssfff") + extension; teacher.TecherImage = "~/Images/" + fileName; teacher.ImageUpload.SaveAs(Path.Combine(Server.MapPath("~/Images/"), fileName)); } using (TableContext db = new TableContext()) { if (teacher.TeacherID == 0) { db.Teachers.Add(teacher); db.SaveChanges(); } else { db.Entry(teacher).State = EntityState.Modified; db.SaveChanges(); } } return(Json(new { success = true, html = GlobalClass.RenderRazorViewToString(this, "ViewAll", GetAllTeacher()), message = "Submitted Successfully" }, JsonRequestBehavior.AllowGet)); } catch (Exception ex) { return(Json(new { success = false, message = ex.Message }, JsonRequestBehavior.AllowGet)); } }
public IHttpActionResult PutAnsatte(string id, Ansatte ansatte) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != ansatte.Brugernavn) { return(BadRequest()); } db.Entry(ansatte).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!AnsatteExists(id)) { return(NotFound()); } else { throw; } } return(StatusCode(HttpStatusCode.NoContent)); }
public IActionResult Create(Item item, string id) { Guid obj = Guid.NewGuid(); string gid = obj.ToString(); item.Id = gid; _context.Items.Add(item); _context.SaveChanges(); return(CreatedAtRoute("GetTodo", new { id = item.Id }, item)); }
public IActionResult Create(ResourceRequisition resourceRequisition) { Guid obj = Guid.NewGuid(); string gid = obj.ToString(); resourceRequisition.Id = gid; _context.ResourceRequisitions.Add(resourceRequisition); _context.SaveChanges(); return(CreatedAtRoute("GetToJobs", new { id = resourceRequisition.Id }, resourceRequisition)); }
public ActionResult Create([Bind(Include = "Id,FirstName,LastName")] Student student) { if (ModelState.IsValid) { db.Students.Add(student); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(student)); }
public IActionResult Create(MyCandidate candidates) { if (candidates.Id == null) { Guid obj = Guid.NewGuid(); string gid = obj.ToString(); candidates.Id = gid; } _context.MyCandidates.Add(candidates); _context.SaveChanges(); var data = _context.MyCandidates.Find(candidates.Id); return(CreatedAtRoute("GetCandidateDetails", new { id = candidates.Id }, candidates)); }
public ActionResult Create(TraineeVM tr) { if (ModelState.IsValid == true) { var teacherslist = db.Teachers.ToList(); ViewBag.TeacherID = new SelectList(teacherslist, "TeacherID", "TeacherName"); var trainee = Mapper.Map <Trainee>(tr); string fileName = Path.GetFileNameWithoutExtension(trainee.Picture.FileName); string extention = Path.GetExtension(trainee.Picture.FileName); HttpPostedFileBase postedFile = trainee.Picture; int length = postedFile.ContentLength; if (extention.ToLower() == ".jpg" || extention.ToLower() == ".jpeg" || extention.ToLower() == ".png") { if (length <= 1000000) { fileName = fileName + extention; tr.UploadImage = "~/Images/" + fileName; fileName = Path.Combine(Server.MapPath("~/Images/"), fileName); tr.Picture.SaveAs(fileName); db.Trainees.Add(trainee); int a = db.SaveChanges(); if (a > 0) { TempData["CreateMessage"] = "<script>alert('Data inserted Successfully')</script>"; ModelState.Clear(); return(RedirectToAction("Index", "Trainee")); } else { TempData["CreateMessage"] = "<script>alert('Data not inserted')</script>"; } } else { TempData["SizeMessage"] = "<script>alert('Image Size Should Less Than 1 MB')</script>"; } } else { TempData["ExtentionMessage"] = "<script>alert('Format Not Supported')</script>"; } } return(View()); }
public string AddUser(RegisteredUser user, int depId, int gid) { using (var db = new TableContext()) { try { var tempstatus = db.statuses.Find(2); var tempGender = db.Genders.Find(gid); var tempdep = db.departments.Find(depId); var temptype = db.Usertypes.Find(2); user.IsDeleted = false; user.Status = tempstatus; user.Department = tempdep; user.UserTypes = temptype; user.Gender = tempGender; db.Rusers.Add(user); db.SaveChanges(); return("User was added"); } catch (Exception ex) { return(ex.Message); } } }
public void ButtonSave_Click(object sender, RoutedEventArgs e) { if (typeMain == typeof(Invoice)) { Invoice newInvoice = (Invoice)Save(); dbTable.Invoices.Add(newInvoice); } else if (typeMain == typeof(Provider)) { Provider newProvider = (Provider)Save(); dbTable.Providers.Add(newProvider); } else if (typeMain == typeof(Payment)) { Payment newPayment = (Payment)Save(); dbTable.Payments.Add(newPayment); } else if (typeMain == typeof(Goods)) { Goods newPayment = (Goods)Save(); dbTable.Goods.Add(newPayment); } dbTable.SaveChanges(); this.Close(); }
public IActionResult AddNewCategory(Categories C) { T.Categories.Add(C); T.SaveChanges(); return(View()); }
public IActionResult SingleFile(IFormFile file) { var tableData = new List <UploadedTable>(); using (StreamReader sr = new StreamReader(file.OpenReadStream())) { string[] headers = sr.ReadLine().Split(','); while (!sr.EndOfStream) { string[] cols = sr.ReadLine().Split(','); tableData.Add(new UploadedTable { col1 = cols[0].ToString(), col2 = cols[1].ToString(), col3 = cols[2].ToString(), col4 = cols[3].ToString(), col5 = cols[4].ToString() }); } } foreach (var t in tableData) { db.Add(t); } db.SaveChanges(); return(RedirectToAction("Index")); }
public void ButtonEdit_Click(object sender, RoutedEventArgs e) { if (typeMain == typeof(Invoice)) { Invoice newInvoice = (Invoice)Save(); var editInvoice = dbTable.Invoices.Find(id); editInvoice.Update(newInvoice); } else if (typeMain == typeof(Provider)) { Provider newProvider = (Provider)Save(); var editProvider = dbTable.Providers.Find(id); editProvider.Update(newProvider); } else if (typeMain == typeof(Payment)) { Payment newPayment = (Payment)Save(); var editPayment = dbTable.Payments.Find(id); editPayment.Update(newPayment); } else if (typeMain == typeof(Goods)) { Goods newPayment = (Goods)Save(); var editPayment = dbTable.Goods.Find(id); editPayment.Update(newPayment); } dbTable.SaveChanges(); this.Close(); }
public IActionResult Create(ResourceRequisition resourceRequisition) { var credentials = new EnvironmentVariablesAWSCredentials(); if (resourceRequisition.Id == null) { Guid obj = Guid.NewGuid(); string gid = obj.ToString(); resourceRequisition.Id = gid; } _context.ResourceRequisitions.Add(resourceRequisition); _context.SaveChanges(); var client = new AmazonSimpleNotificationServiceClient(credentials, RegionEndpoint.APSouth1); SendMessage(client, resourceRequisition).Wait(); return(CreatedAtRoute("GetToJobs", new { id = resourceRequisition.Id }, resourceRequisition)); }
public static void SaveInformation(string url, string body) { using (TableContext db = new TableContext()) { db.Table.Add(new Table { URL = url, Body = body }); db.SaveChanges(); } }
public ActionResult Create(Entry entry) { if (ModelState.IsValid) { db.Entries.Add(entry); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(entry)); }
public IActionResult Reservation(int TableNumber, Owner owner) { db.Owner.Add(owner); foreach (var table in db.Table) { if (table.TableNumber == TableNumber) { table.Status = "Занят"; table.OwnerId = owner.IDOwner; } } db.SaveChanges(); ViewBag.TableNumber = TableNumber; ViewBag.OwnerID = owner.IDOwner; ViewBag.OwnerName = owner.Name; ViewBag.OwnerSurname = owner.Surname; ViewBag.OwnerPatronymiv = owner.Patronymic; return(View()); }
public string UpdateAddress(int id, Address upadd, int?subID, int?typeId) { Address tempaddress = new Address(); using (var db = new TableContext()) { var readdress = db.addresses.Find(id); tempaddress = readdress; try { if (!string.IsNullOrEmpty(upadd.UnitNumber)) { tempaddress.UnitNumber = upadd.UnitNumber; } if (upadd.StreetName != "") { tempaddress.StreetName = upadd.StreetName; } if (!string.IsNullOrEmpty(upadd.ComplexNumber)) { tempaddress.ComplexNumber = upadd.ComplexNumber; } if (typeId != null) { var type = db.addresstypes.Where(s => s.AddressTypeID == typeId).FirstOrDefault(); tempaddress.Addresstypes = type; } if (subID != null) { var sub = db.surbubs.Where(s => s.SurbubID == subID).FirstOrDefault(); tempaddress.sub = sub; } db.Entry(tempaddress).State = System.Data.Entity.EntityState.Modified; db.SaveChanges(); return("address was updated"); } catch (Exception ex) { return(ex.Message); } } }
public string SoftDeleteUser(int id) { using (var db = new TableContext()) { var tempuser = db.Rusers.Where(s => s.RegisteredUserID == id).FirstOrDefault(); //tempuser.IsDeleted=true; tempuser.IsDeleted = true; db.Entry(tempuser).State = System.Data.Entity.EntityState.Modified; db.SaveChanges(); } return("User was Deleted"); }
public IActionResult create(SkillSet skill) { Guid obj = Guid.NewGuid(); string gid = obj.ToString(); if (skill.Parent == "") { skill.Id = gid; skill.Parent = null; _context.SkillSets.Add(skill); _context.SaveChanges(); } else { skill.Id = gid; _context.SkillSets.Add(skill); _context.SaveChanges(); } return(CreatedAtRoute("GetToskills", new { id = skill.Id }, skill)); }
public string DeactivateUser(int id) { using (var db = new TableContext()) { var st = db.statuses.Find(2); var tempuser = db.Rusers.Where(s => s.RegisteredUserID == id).FirstOrDefault(); tempuser.Status = st; db.Entry(tempuser).State = System.Data.Entity.EntityState.Modified; db.SaveChanges(); } return("User was Deactivated"); }
public ActionResult SignUp(UserDTO userDTO) { var db = new TableContext(); var user = UserCommon.ConvertDTOtoBO(userDTO); if (ModelState.IsValid) { TempData["submitMessage"] = "success"; db.Users.Add(user); db.SaveChanges(); } return(View()); }
public ActionResult CreateUpdateEmp(ExamDetailDTO examDetail) { if (examDetail.ExamDetailData.ExamDetailID == 0) { var traineeList = db.Trainees.ToList(); ViewBag.TraineeID = new SelectList(traineeList, "TraineeID", "TraineeName"); db.ExamDetails.Add(examDetail.ExamDetailData); db.SaveChanges(); } else { var dataInDb = db.ExamDetails.FirstOrDefault(a => a.ExamDetailID == examDetail.ExamDetailData.ExamDetailID); dataInDb.ExamName = examDetail.ExamDetailData.ExamName; dataInDb.ExamDate = examDetail.ExamDetailData.ExamDate; dataInDb.MCQ = examDetail.ExamDetailData.MCQ; dataInDb.Evidence = examDetail.ExamDetailData.Evidence; dataInDb.TraineeID = examDetail.ExamDetailData.TraineeID; db.SaveChanges(); } return(RedirectToAction("CreateUpdateEmp")); }
public void Seed() { var candidateContent = new MyCandidate(); candidateContent.Id = "9999"; candidateContent.ResourceRequisition = "Seed Manager"; candidateContent.CandidateEmail = "*****@*****.**"; candidateContent.Stages = 3; candidateContent.ResumeText = "Seed Resume"; candidateContent.ResumeUpload = ""; candidateContent.PanelDeadline = new DateTime(); _context.MyCandidates.Add(candidateContent); _context.SaveChanges(); }
public ActionResult Delete(int id) { try { using (TableContext db = new TableContext()) { Teacher teacher = db.Teachers.Where(x => x.TeacherID == id).FirstOrDefault <Teacher>(); db.Teachers.Remove(teacher); db.SaveChanges(); } return(Json(new { success = true, html = GlobalClass.RenderRazorViewToString(this, "ViewAll", GetAllTeacher()), message = "Deleted Successfully" }, JsonRequestBehavior.AllowGet)); } catch (Exception ex) { return(Json(new { success = false, message = ex.Message }, JsonRequestBehavior.AllowGet)); } }
public void AddUpTestMethod() { UserPO info; using (var table = new TableContext <UserPO>()) { info = table.TableSet.Desc(o => o.ID).ToInfo(); table.TableSet.Where(o => o.ID == info.ID).Append(o => new { o.LoginCount }, 4).AddUp(); table.SaveChanges(); var info2 = table.TableSet.Desc(o => o.ID).ToInfo(); Assert.IsTrue(info2.LoginCount == info.LoginCount + 4); } TableContext <UserPO> .Data.Where(o => o.ID == info.ID).Update(new UserPO() { UserName = "******" }); Assert.IsTrue(TableContext <UserPO> .Data.Desc(o => o.ID).ToInfo().UserName == "bb"); }
public void UpdateTestMethod() { var ID = 0; using (var table = new TableContext <UserPO>()) { ID = table.TableSet.Desc(o => o.ID).ToInfo().ID.GetValueOrDefault(); table.TableSet.Where(o => o.ID == ID).Update(new UserPO() { UserName = "******" }); table.SaveChanges(); Assert.IsTrue(table.TableSet.Desc(o => o.ID).ToInfo().UserName == "zz"); } TableContext <UserPO> .Data.Where(o => o.ID == ID).Update(new UserPO() { UserName = "******" }); Assert.IsTrue(TableContext <UserPO> .Data.Desc(o => o.ID).ToInfo().UserName == "bb"); }
public string UpdateUser(int id, RegisteredUser updateinfo) { RegisteredUser temp = new RegisteredUser(); using (var db = new TableContext()) { var tempuser = db.Rusers.Where(s => s.RegisteredUserID == id).FirstOrDefault(); temp = tempuser; if (!string.IsNullOrEmpty(updateinfo.EmailAddress)) { temp.EmailAddress = updateinfo.EmailAddress; } if (!string.IsNullOrEmpty(updateinfo.FirstName)) { temp.FirstName = updateinfo.FirstName; } if (!string.IsNullOrEmpty(updateinfo.LastName)) { temp.LastName = updateinfo.LastName; } if (!string.IsNullOrEmpty(updateinfo.Password)) { temp.Password = updateinfo.Password; } db.Entry(temp).State = System.Data.Entity.EntityState.Modified; db.SaveChanges(); } return("user was updated"); }
private static void CheckAndUpdateMetadataLastUpdateDate(string metadataSet, string entitySet, string entityKind, DateTime lastUpdateDate, DataLoaderParams Params) { var context = new TableContext(s_account.TableEndpoint.ToString(), s_account.Credentials, Params) { RetryPolicy = RetryPolicies.RetryExponential(RetryPolicies.DefaultClientRetryCount, RetryPolicies.DefaultClientBackoff) }; string query = string.Format(s_metadataEntityQueryTemplate, metadataSet, entitySet, entityKind); List<TableEntity> results = context.Execute<TableEntity>(new Uri(query, UriKind.Relative)).ToList(); if (results.Count == 1) { DateTime oldLastUpdateDate = new TableMetadataEntity(results[0]).LastUpdateDate; if (oldLastUpdateDate > lastUpdateDate) throw new MetadataOutdatedException(oldLastUpdateDate, lastUpdateDate); results[0].UpdateProperty(DataLoaderConstants.PropNameLastUpdateDate, lastUpdateDate); context.UpdateObject(results[0]); context.SaveChanges(); } else if (results.Count > 1) { throw new DuplicateEntityException(query); } }
private static void DeleteMetadata(string metadataSet, string entitySet, string entityKind, DataLoaderParams parameters) { var context = new TableContext(s_account.TableEndpoint.ToString(), s_account.Credentials, parameters) { RetryPolicy = RetryPolicies.RetryExponential(RetryPolicies.DefaultClientRetryCount, RetryPolicies.DefaultClientBackoff) }; string query = string.Format(s_metadataEntityQueryTemplate, metadataSet, entitySet, entityKind); List<TableEntity> results = context.Execute<TableEntity>(new Uri(query, UriKind.Relative)).ToList(); if (results.Count == 1) { context.DeleteObject(results.First()); context.SaveChanges(); } else if (results.Count > 1) { throw new DuplicateEntityException(query); } }
private void StoreEntity(string entitySetName, string parKeyPropName, string rowKeyPropName, Entity entity) { var account = CloudStorageAccount.Parse(ConfigurationManager.AppSettings["DataConnectionString"]); var context = new TableContext(account.TableEndpoint.ToString(), account.Credentials, _parameters) { RetryPolicy = RetryPolicies.RetryExponential(5, new TimeSpan(0, 0, 1)) }; var kmlSnippet = (string)entity[DataLoaderConstants.PropNameKmlSnippet]; if (kmlSnippet != null && kmlSnippet.Length > 32 * 1024) { string blobName = Guid.NewGuid().ToString(); string containerName = entitySetName.ToLower(); StoreKmlSnippetAsBlob(containerName, blobName, kmlSnippet); entity[DataLoaderConstants.PropNameKmlSnippet] = string.Format(DataLoaderConstants.KmlSnippetReference, containerName, blobName); } var kmlCoords = (string)entity[DataLoaderConstants.PropNameKmlCoords]; if (kmlCoords != null && kmlCoords.Length > 32 * 1024) { string blobName = Guid.NewGuid().ToString(); string containerName = entitySetName.ToLower(); StoreKmlSnippetAsBlob(containerName, blobName, kmlCoords); entity[DataLoaderConstants.PropNameKmlCoords] = string.Format(DataLoaderConstants.KmlSnippetReference, containerName, blobName); } TableEntity tableEntity = null; bool isUpdate = false; if (_parameters != null) { string parKey; object pk = entity[parKeyPropName]; if (string.IsNullOrEmpty(entity.Number)) { parKey = (pk != null) ? ConvertToProperPartitionKey(ConvertValueToString(pk)) : entity.Id.ToString(); } else { parKey = entity.Number; } string rowKey = null; object rk = entity[rowKeyPropName]; if (rowKeyPropName.ToLower() == DataLoaderConstants.ValueUniqueAutoGen) { rowKey = Guid.NewGuid().ToString(); } else { rowKey = (rk != null) ? ConvertValueToString(entity[rowKeyPropName]) : Guid.NewGuid().ToString(); } //try to load entity from storage if (_overwriteMode == TableOverwriteMode.Add || _overwriteMode == TableOverwriteMode.Update) { tableEntity = LoadEntity(context, entitySetName, rowKeyPropName, rowKey, rk, parKeyPropName, parKey, pk); if (tableEntity != null && _overwriteMode == TableOverwriteMode.Add) throw new EntityAlreadyExistsException(entitySetName, rowKeyPropName, rowKey, parKeyPropName, parKey); if (tableEntity != null) { tableEntity.UpdateEntity(entity); isUpdate = true; } } //if not found, create new if (tableEntity == null) tableEntity = new TableEntity(entity, parKey, rowKey); } else { tableEntity = new TableEntity(entity); } if (!isUpdate) context.AddObject(entitySetName, tableEntity); else context.UpdateObject(tableEntity); try { context.SaveChanges(); } catch (StorageClientException e) { if (e.ErrorCode == StorageErrorCode.ResourceAlreadyExists && e.StatusCode == HttpStatusCode.Conflict) { throw new DuplicateEntityException(tableEntity.ToString(), e); } } catch (DataServiceRequestException e) { if (e.InnerException != null && ((DataServiceClientException)e.InnerException).StatusCode == (int)HttpStatusCode.Conflict) { throw new DuplicateEntityException(tableEntity.ToString(), e); } } }
private static void DeleteRdfMetadata(string metadataSet, string entitySet, DataLoaderParams parameters) { var context = new TableContext(s_account.TableEndpoint.ToString(), s_account.Credentials, parameters) { RetryPolicy = RetryPolicies.RetryExponential(RetryPolicies.DefaultClientRetryCount, RetryPolicies.DefaultClientBackoff) }; string query = string.Format(s_metadataRdfQueryTemplate, metadataSet, entitySet); List<TableEntity> results = context.Execute<TableEntity>(new Uri(query, UriKind.Relative)).ToList(); if (results.Count > 0) { foreach (TableEntity i in results) { context.DeleteObject(i); context.SaveChanges(); } } }