public JsonResult CreateCompany(CompanyCreateModel createModel) { if (service.ExistsCompanyWithEniroId(createModel.EniroId)) { createModel.CreateMsg = "Företaget med Eniroid '" + createModel.EniroId + "' finns redan i systemet!"; return Json(createModel, JsonRequestBehavior.AllowGet); } createModel.Id = service.CreateCompany(createModel); return Json(createModel, JsonRequestBehavior.AllowGet); }
public static long CreateCompany(CompanyCreateModel createModel) { var db = new DataContext(); var c = new Company(createModel.IsRestaurant) { Name = createModel.CompanyName, Organisationnr = createModel.Organisationnr, Information = createModel.Information, Notes = createModel.Notes, Latitude = createModel.Latitude, Longitude = createModel.Longitude, EniroId = createModel.EniroId, Email = createModel.Email, Url = createModel.Url, //PhoneNumbers = model.PhoneNumbers.Select(p => new PhoneNumber { // Number = p.Number, // Type = (PhoneNumberType) p.Type // }).ToList(), Adress = new Adress { PostCode = createModel.PostCode, Street = createModel.Street, PostArea = createModel.PostArea } }; try { db.Companies.Add(c); //c.Adress.City = db.Cities.Find(c.Adress.City.Id); if (createModel.IsRestaurant) { var r = new Restaurant(); var area = db.LunchAreas.Find(createModel.LunchAreaId); r.SetDataFromCompany(c, area); r.Areas.Add(area); db.Restaurants.Add(r); } db.SaveChanges(); return c.Id; } catch (Exception ex) { throw new Exception(); } }
//public IEnumerable<RestaurantViewModel> GetRestaurants() //{ // return RestaurantManager.GetRestaurants(); //} //public IEnumerable<DishViewModel> GetDishes() //{ // return RestaurantManager.GetDishes(); //} public long CreateCompany(CompanyCreateModel createModel) { return CompanyManager.CreateCompany(createModel); }