public IHttpActionResult Put([FromUri] string section, [FromBody] Sections SectionEntity) { using (ServicesEntities db = new ServicesEntities()) { try { var UpdatedEntity = db.Sections.Where(s => s.Section == section).FirstOrDefault(); if (UpdatedEntity != null) { UpdatedEntity.City = SectionEntity.City; UpdatedEntity.Location = SectionEntity.Location; UpdatedEntity.Name = SectionEntity.Name; db.Entry(UpdatedEntity).State = System.Data.Entity.EntityState.Modified; db.SaveChanges(); return(Ok()); } else { return(BadRequest("Записи с данным идентификатором сервера не найдено.")); } } catch (Exception ex) { return(BadRequest(ex.ToString())); } } }
public void insertRegCode(string userId, int regCode) { var query = from uprofile in serviceContext.Users where uprofile.UserId == userId select uprofile; var q = query.SingleOrDefault(); q.RegCode = regCode.ToString(); try { serviceContext.Entry(q).State = EntityState.Modified; serviceContext.SaveChanges(); } catch { throw; } }
public JsonResult RemoveService(int id) { using (var db = new ServicesEntities()) { Service service = db.Services.Find(id); if (service == null) { return(Json(new { success = false })); } db.Services.Remove(service); db.SaveChanges(); return(Json(new { success = true })); } }
public JsonResult UpdateService(Service service) { using (var db = new ServicesEntities()) { var serviceUpdated = db.Services.Find(service.ServiceId); if (serviceUpdated == null) { return(Json(new { success = false })); } else { serviceUpdated.Description = service.Description; serviceUpdated.Date = service.Date; serviceUpdated.Type = service.Type; db.SaveChanges(); return(Json(new { success = true })); } } }
public JsonResult AddService(Service service) { if (service != null) { using (var db = new ServicesEntities()) { try { db.Services.Add(service); db.SaveChanges(); } catch (Exception exception) { Console.WriteLine(exception.Message); } return(Json(new { success = true })); } } return(Json(new { success = false })); }
public IHttpActionResult Post([FromUri] string section, [FromBody] Sections SectionEntity) { using (ServicesEntities db = new ServicesEntities()) { try { if (db.Sections.Any(s => s.Section == section)) { return(BadRequest("Запись с данным идентификатором сервера уже создана.")); } SectionEntity.Id = Guid.NewGuid(); SectionEntity.Section = section; db.Sections.Add(SectionEntity); db.SaveChanges(); return(Ok()); } catch (Exception ex) { return(BadRequest(ex.ToString())); } } }
public async Task <ActionResult> ProfileSetup(ProfilingModel model, HttpPostedFileBase uploadedFile) { if (reg.UserProfile(User.Identity.GetUserId()).Count != 0) { TempData["duplicate"] = "Please you already have an account on FindUs try and Login using ur details or recover your password"; TempData["Success"] = "You have completed this stage, go to add a service"; return(RedirectToAction("ProfileSetup")); } var validImageTypes = new string[] { "image/gif", "image/jpeg", "image/pjpeg", "image/png" }; if (uploadedFile == null || uploadedFile.ContentLength == 0) { ModelState.AddModelError("ImageUpload", "This field is required"); return(RedirectToAction("ProfileSetup")); } else if (!validImageTypes.Contains(uploadedFile.ContentType)) { ModelState.AddModelError("ImageUpload", "Please choose either a GIF, JPG or PNG image."); return(RedirectToAction("ProfileSetup")); } if (model != null && uploadedFile != null) { UserProfile profile = new UserProfile(); try { //var user = new ApplicationUser { UserName = model.Email, Email = model.Email }; profile.countryId = model.CountryId; profile.StateId = model.StateId; profile.LGAId = model.LGAId; profile.HomeAddress = model.HomeAddress; profile.OfficialPhoneNumber = model.OfficialPhone; string ImageName = User.Identity.GetUserId() + System.IO.Path.GetFileName(uploadedFile.FileName); string physicalPath = Server.MapPath("~/images/" + ImageName); uploadedFile.SaveAs(physicalPath); profile.Image = ImageName; profile.MissionStatement = model.MissionStatement; profile.Skills = model.Skills; profile.UserId = User.Identity.GetUserId().ToString(); serviceContext.UserProfiles.Add(profile); serviceContext.SaveChanges(); TempData["Success"] = "Profile created successfuly.Please click on Add Service tab to continue"; //string code = await UserManager.GenerateEmailConfirmationTokenAsync(user.Id); //var callbackUrl = Url.Action("ConfirmEmail", "Account", new { userId = user.Id, code = code }, protocol: Request.Url.Scheme); //await UserManager.SendEmailAsync(user.Id, "Confirm your account", "Please confirm your account by clicking <a href=\"" + callbackUrl + "\">here</a>"); } catch (Exception ex) { TempData["ex"] = ex.Message; } //return View(model); } return(RedirectToAction("ProfileSetup")); }