public IActionResult Add([FromBody] AddModelView data) { if (data != null && !string.IsNullOrEmpty(data.Name)) { AttributeSet attSet = new AttributeSet { Name = data.Name }; foreach (EcommerShop.Models.ModelBusiness.Attribute att in data.Attributes) { if (string.IsNullOrEmpty(att.Name) || string.IsNullOrEmpty(att.Code)) { continue; } attSet.JointAttributeSet.Add(new JointAttributeSet { AttributeSetId = attSet.Id, AttributeId = att.Id, Attribute = att, AttributeSet = attSet }); } using (var transaction = _context.Database.BeginTransaction()) { try { _context.Add(attSet); _context.SaveChanges(); transaction.Commit(); } catch (Exception e) { transaction.Rollback(); Console.WriteLine("Error occurred."); return(Json(new { statusCode = 500, msg = "Server đã xảy ra lỗi vui lòng quay lại sau!" })); }; } return(Json(new { statusCode = 200, msg = "Bạn đã thêm danh mục " + attSet.Name + " với " + attSet.JointAttributeSet.Count + " thuộc tính!" })); } return(Json(new { statusCode = 400, msg = "Tên danh mục hoặc thuộc tính danh mục chưa điền!" })); }
protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e) { base.OnNavigatedTo(e); if (newInstance) { if (viewModel == null) { if (State.Count > 0) { viewModel = (AddModelView)State["viewModel"]; if (viewModel.chargeRadioButton == true) { if (IsolatedStorageSettings.ApplicationSettings.Contains("situation")) { if (IsolatedStorageSettings.ApplicationSettings["situation"].Equals(false)) { IsolatedStorageSettings.ApplicationSettings["situation"] = true; } } } else { if (IsolatedStorageSettings.ApplicationSettings.Contains("situation")) { if (IsolatedStorageSettings.ApplicationSettings["situation"].Equals(true)) { IsolatedStorageSettings.ApplicationSettings["situation"] = false; } } } } else { viewModel = new AddModelView(); } } this.DataContext = viewModel; } newInstance = false; }