public ActionResult Create() { Company company = new Company(); return View(company); }
public async Task<IHttpActionResult> UpdatePage(Company comment,string tags) { //if (!ModelState.IsValid) //{ // return BadRequest(); //} db.Entry(comment).State = EntityState.Modified; try { await db.SaveChangesAsync(); } catch (DbEntityValidationException e) { string s = e.ToString(); List<string> errorMessages = new List<string>(); foreach (DbEntityValidationResult validationResult in e.EntityValidationErrors) { string entityName = validationResult.Entry.Entity.GetType().Name; foreach (DbValidationError error in validationResult.ValidationErrors) { errorMessages.Add(entityName + "." + error.PropertyName + ": " + error.ErrorMessage); } } } catch (Exception e) { string s = e.ToString(); } var returnTags = await UpdateTags(tags, comment.Id); return Ok(returnTags); }
// GET: /Company/Create public void SaveTags(Company ad) { string s = Request["tags"]; string[] values = s.Split(','); Inspinia_MVC5_SeedProject.Models.Tag[] tags = new Inspinia_MVC5_SeedProject.Models.Tag[values.Length]; CompanyTag[] qt = new CompanyTag[values.Length]; for (int i = 0; i < values.Length; i++) { values[i] = values[i].Trim(); string ss = values[i]; if (ss != "") { var data = db.Tags.FirstOrDefault(x => x.name.Equals(ss, StringComparison.OrdinalIgnoreCase)); tags[i] = new Inspinia_MVC5_SeedProject.Models.Tag(); if (data != null) { tags[i].Id = data.Id; } else { tags[i].name = values[i]; tags[i].time = DateTime.UtcNow; tags[i].createdBy = User.Identity.GetUserId(); db.Tags.Add(tags[i]); } } else { tags[i] = null; } } try { db.SaveChanges(); } catch (Exception e) { string sb = e.ToString(); } for (int i = 0; i < values.Length; i++) { if (tags[i] != null) { qt[i] = new CompanyTag(); qt[i].companyId = ad.Id; qt[i].tagId = tags[i].Id; db.CompanyTags.Add(qt[i]); } } }
public async Task<IHttpActionResult> HeadOfficeLocation(Company branch, string city, string popularPlace, string exectLocation) { // var branch = await db.Companies.FindAsync(companyId); if (city != null) { var citydb = db.Cities.FirstOrDefault(x => x.cityName.Equals(city, StringComparison.OrdinalIgnoreCase)); if (citydb == null) { City cit = new City(); cit.cityName = city; cit.addedBy = User.Identity.GetUserId(); cit.addedBy = User.Identity.GetUserId(); cit.addedOn = DateTime.UtcNow; db.Cities.Add(cit); await db.SaveChangesAsync(); // loc.cityId = cit.Id; branch.cityId = cit.Id; if (popularPlace != null) { popularPlace pop = new popularPlace(); pop.cityId = cit.Id; pop.name = popularPlace; pop.addedBy = User.Identity.GetUserId(); pop.addedOn = DateTime.UtcNow; db.popularPlaces.Add(pop); await db.SaveChangesAsync(); // loc.popularPlaceId = pop.Id; branch.popularPlaceId = pop.Id; } } else { // loc.cityId = citydb.Id; branch.cityId = citydb.Id; if (popularPlace != null) { var ppp = db.popularPlaces.FirstOrDefault(x => x.City.cityName.Equals(city, StringComparison.OrdinalIgnoreCase) && x.name.Equals(popularPlace, StringComparison.OrdinalIgnoreCase)); if (ppp == null) { popularPlace pop = new popularPlace(); pop.cityId = citydb.Id; pop.name = popularPlace; pop.addedBy = User.Identity.GetUserId(); pop.addedOn = DateTime.UtcNow; db.popularPlaces.Add(pop); await db.SaveChangesAsync(); // loc.popularPlaceId = pop.Id; branch.popularPlaceId = pop.Id; } else { // loc.popularPlaceId = ppp.Id; branch.popularPlaceId = ppp.Id; } } } branch.exectLocation = exectLocation; try { db.Entry(branch).State = EntityState.Modified; await db.SaveChangesAsync(); } catch (Exception e) { string s = e.ToString(); } } //var ret = await (from br in db.CompanyOffices // where br.Id.Equals(branch.Id) // select new // { // id = br.Id, // cityId = br.cityId, // cityName = br.City.cityName, // popularPlace = br.popularPlace.name, // popularPlaceId = br.popularPlaceId, // contactNo1 = br.contactNo1, // contactNo2 = br.contactNo2, // since = br.since, // exectLocation = br.exectLocation, // }).FirstOrDefaultAsync(); return Ok("Done"); }