public Site Add(Site item) { if (item == null) { throw new ArgumentNullException("item"); } item.SiteId = _nextId; db.Sites.Add(item); db.SaveChanges(); return(item); }
public RedirectToRouteResult AddNewImageFolder([Bind(Include = "FileName, SiteIds")] ImageViewModel model, HttpPostedFileBase image = null) { if (ModelState.IsValid) { ImgObj img = new ImgObj { ImgObjId = model.ImageId, FileName = model.FileName, }; img.FileContentType = image.ContentType; img.ImageData = new byte[image.ContentLength]; image.InputStream.Read(img.ImageData, 0, image.ContentLength); if (model.SiteIds != null) { foreach (var id in model.SiteIds) { var siteId = int.Parse(id); var site = db.Sites.Find(siteId); try { img.Sites.Add(site); } catch (Exception ex) { return(RedirectToAction("Error", new HandleErrorInfo(ex, "Site", "Manager"))); } } } try { db.ImgObjs.Add(img); db.SaveChanges(); } catch (Exception ex) { return(RedirectToAction("Error", new HandleErrorInfo(ex, "Site", "Manager"))); } TempData["message"] = string.Format("{0} has been included.", img.FileName); return(RedirectToAction("Manager", new SiteViewModel { ReturnUrl = model.ReturnUrl })); } TempData["Errmessage"] = string.Format("Failure."); return(RedirectToAction("Manager", new SiteViewModel { ReturnUrl = model.ReturnUrl })); }
public HttpResponseMessage Put(int id, [FromBody] Site site) { try { using (RadioDbContext context = new RadioDbContext()) { var entity = context.Sites.FirstOrDefault(e => e.SiteId == id); if (entity != null) { entity.Name = site.Name; entity.Address = site.Address; entity.AppNo = site.AppNo; entity.Category = site.Category; entity.City = site.City; entity.Latitude = site.Latitude; entity.Longitude = site.Longitude; entity.Post = site.Post; entity.State = site.State; context.SaveChanges(); return(Request.CreateResponse(HttpStatusCode.OK, entity.Name + " has been updated!")); } else { return(Request.CreateErrorResponse(HttpStatusCode.NotFound, "Id " + entity.SiteId.ToString() + "Not found!")); } } } catch (Exception ex) { return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ex)); } }
public HttpResponseMessage Post([FromBody] Site site, HttpPostedFileBase image) { try { site.LastModified = DateTime.UtcNow; site.LastModifiedBy = User.Identity.Name; db.Sites.Add(site); db.SaveChanges(); var message = Request.CreateResponse(HttpStatusCode.Created, site); message.Headers.Location = new Uri(Request.RequestUri + site.SiteId.ToString()); return(message); } catch (Exception ex) { return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ex)); } }
public HttpResponseMessage Delete(int id) { try { using (RadioDbContext context = new RadioDbContext()) { var entity = context.Sites.FirstOrDefault(e => e.SiteId == id); if (entity == null) { return(Request.CreateErrorResponse(HttpStatusCode.NotFound, "Site Id =" + entity.SiteId + " was not found.")); } else { context.Sites.Remove(context.Sites.FirstOrDefault(e => e.SiteId == id)); context.SaveChanges(); return(Request.CreateResponse(HttpStatusCode.OK)); } } } catch (Exception ex) { return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ex)); } }
public int AddImgObj(ImgObj obj) { db.ImgObjs.Add(obj); db.SaveChanges(); return(0); }
public async Task <ActionResult> Index([Bind(Include = "Id,Email,Name,Phone,Message")] EmailViewModel model) { if (!await RecaptchaServices.Validate(Request)) { TempData["ErrMessage"] = string.Format("Your request was denied -- Google Recaptcha v.2.0"); } if (ModelState.IsValid) { GuestEmail set = new GuestEmail { Id = model.Id, Email = model.Email, Name = model.Name, Phone = model.Phone, Message = model.Message, }; try { var credentialUserName = ConfigurationManager.AppSettings["SendGrid_UserName"]; var sendGridPassword = ConfigurationManager.AppSettings["SendGrid_Password"]; var message = new MailMessage(); using (var smtp = new SmtpClient("smtp.sendgrid.net", Convert.ToInt32(587))) { message.To.Add(new MailAddress(model.Email)); String bodyBuilder = ""; message.From = new MailAddress("*****@*****.**"); message.Subject = "RadProSite Auto Response"; using (StreamReader read = new StreamReader(Server.MapPath("~/Views/Shared/EmailTemplates/AutoResponseTheme.html"))) { bodyBuilder += read.ReadToEnd(); } message.AlternateViews.Add(AlternateView.CreateAlternateViewFromString(bodyBuilder, null, MediaTypeNames.Text.Html)); smtp.DeliveryMethod = System.Net.Mail.SmtpDeliveryMethod.Network; smtp.UseDefaultCredentials = false; NetworkCredential credentials = new NetworkCredential(credentialUserName, sendGridPassword); smtp.EnableSsl = true; smtp.Credentials = credentials; await smtp.SendMailAsync(message); } set.Status = "Potential"; set.UserIpAddress = HttpContext.Request.UserHostAddress; set.ReceivedDate = DateTime.UtcNow; db.GuestEmails.Add(set); TempData["message"] = string.Format("Yes " + "{0} we received your email.", model.Name); db.SaveChanges(); } catch (Exception ex) { return(View("Error", new HandleErrorInfo(ex, "Home", "Index"))); } return(RedirectToAction("Index")); } else { TempData["ErrMessage"] = string.Format("Your contact form was incomplete!"); return(View(model)); } }
public int AddLease(Email entity) { db.Emails.Add(entity); db.SaveChanges(); return(0); }