public IHttpActionResult PutAppLog(int id, AppLog appLog) { if (!ModelState.IsValid) { return BadRequest(ModelState); } if (id != appLog.Id) { return BadRequest(); } db.Entry(appLog).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!AppLogExists(id)) { return NotFound(); } else { throw; } } return StatusCode(HttpStatusCode.NoContent); }
public IHttpActionResult PostAppLog(AppLog appLog) { if (!ModelState.IsValid) { return BadRequest(ModelState); } db.AppLog.Add(appLog); db.SaveChanges(); return CreatedAtRoute("DefaultApi", new { id = appLog.Id }, appLog); }
public string PostPeople(StockUser v) { try { db.StockUsers.Add(v); db.SaveChanges(); } catch (Exception ex) { var x = new AppLog() { LogDate = DateTime.Now, msg = "inside save" + ex.Message + ex.InnerException.Message }; db.AppLog.Add(x); db.SaveChanges(); throw; } return "{'Id':1,'UserName':'******'}"; }
// GET: ShowDocs public ActionResult Index() { try { return View(db.Documents.ToList().OrderBy(x => x.Property.Name)); } catch (Exception ex) { var a = new AppLog() { LogDate = DateTime.Now, msg = ex.Message + " " + ex.InnerException.Message }; db.AppLog.Add(a); db.SaveChanges(); return View(); } }
public int PostDocuments(DocumentsViewModel documents) { // if (!ModelState.IsValid) // { // return BadRequest(ModelState); // } try { AutoMapper.Mapper.CreateMap<DocumentsViewModel, Documents>(); var d = AutoMapper.Mapper.Map<DocumentsViewModel, Documents>(documents); if (d.fileContent != null && d.fileContent.Length > 0) { string base64 = documents.fileContent.Replace("data:image/jpeg;base64,", "");// load base 64 code to this variable from js Byte[] bitmapData = new Byte[base64.Length]; bitmapData = Convert.FromBase64String(FixBase64Helper.FixBase64ForImage(base64)); d.fileContent = bitmapData; } if (documents.Id != 0) { db.Documents.Attach(d); db.Entry(d).State = EntityState.Modified; } else { db.Documents.Add(d); } db.SaveChanges(); return d.Id; //var client = new SmtpClient("smtp.gmail.com", 587) //{ // Credentials = new NetworkCredential("*****@*****.**", "pflm74616"), // EnableSsl = true //}; ////MailAddress from = new MailAddress("*****@*****.**"); ////MailAddress to = new MailAddress("*****@*****.**"); ////MailAddress cc = new MailAddress("*****@*****.**"); ////MailMessage msg = new MailMessage("*****@*****.**", "*****@*****.**", "New ManageMe Document: " + documents.Notes, "test"); ////msg.To.Add(cc); //////Stream s = null; //////var writer = new BinaryWriter(s); //////writer.Write(documents.fileContent); //////Attachment a = new Attachment(s, documents.Notes + ".jpeg"); ////msg.Body = "Type: " + d.SubType.SubTypeName; //////msg.Attachments.Add(a); ////client.Send(msg); } catch (Exception ex) { //db.Documents.Remove(db.Documents.Where(x => x.Id == documents.Id).FirstOrDefault()); var log = new AppLog() { LogDate = DateTime.Now, msg = ex.InnerException.Message }; db.AppLog.Add(log); db.SaveChanges(); throw; //return Conflict(); } //var b = new AppLog() { logDate = DateTime.Now, msg = "after save" }; //db.AppLog.Add(b); //db.SaveChanges(); }
public IHttpActionResult PostVendors(Vendors v) { try { db.Vendors.Add(v); db.SaveChanges(); } catch(Exception ex) { var x = new AppLog() { LogDate = DateTime.Now, msg = "inside save"+ex.Message+ex.InnerException.Message }; db.AppLog.Add(x); db.SaveChanges(); } return CreatedAtRoute("DefaultApi", new { id = v.Id }, v); }