public Response <Producto> Create(Producto producto) { //if (producto. == 0) //{ // return new Response<Producto> { IsSuccess = false, Answer = null, Message = "No pertenece a empresa" }; //} if (string.IsNullOrEmpty(producto.Marca)) { return(new Response <Producto> { IsSuccess = false, Answer = null, Message = "Campo 'marca' vacio" }); } if (string.IsNullOrEmpty(producto.Modelo)) { return(new Response <Producto> { IsSuccess = true, Answer = null, Message = "Campo 'modelo' vacio" }); } if (string.IsNullOrEmpty(producto.Nombre)) { return(new Response <Producto> { IsSuccess = true, Answer = null, Message = "Campo 'nombre' vacio" }); } if (producto.PrecioNormal <= 0) { return(new Response <Producto> { IsSuccess = true, Answer = null, Message = "El precio debe ser mayor a 0" }); } if (string.IsNullOrEmpty(producto.Temporada)) { return(new Response <Producto> { IsSuccess = true, Answer = null, Message = "Campo 'Temporada' vacio" }); } if (producto.Categoria.IdCategoria == 0) { return(new Response <Producto> { IsSuccess = true, Answer = null, Message = "Seleccione categoría" }); } if (producto.Stock <= 0) { return(new Response <Producto> { IsSuccess = true, Answer = null, Message = "Stock debe ser mayor a 0" }); } Bd.Productos.Add(producto); Bd.SaveChanges(); return(new Response <Producto> { IsSuccess = true, Answer = producto, Message = "Producto creado" }); }
public ActionResult Create([Bind(Include = "NewsID,Title,Content,PostDate")] News news) { if (ModelState.IsValid) { db.News.Add(news); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(news)); }
public ActionResult Create([Bind(Include = "NewsPhotoID,NewsID,PhotoLocation")] NewsPhotoDetail newsPhoto) { if (ModelState.IsValid) { db.NewsPhotoDetails.Add(newsPhoto); db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.NewsID = new SelectList(db.News, "NewsID", "Title", newsPhoto.NewsID); return(View(newsPhoto)); }
public ActionResult Create([Bind(Include = "ManagementPersonName,Info")] ManagementBiography managementBiography) { if (ModelState.IsValid) { //encodinimas keliant i DB managementBiography.Info = HttpUtility.HtmlEncode(managementBiography.Info); db.ManagementBiographies.Add(managementBiography); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(managementBiography)); }
public void SelectAttachModified() { Logger.Log.Error("### SelectAttachModified #############################################"); t_Account account = null; using (var context = new CommonContext()) { account = (from row in context.Account select row).Take(1).ToList().Single(); account.Cash += 1; account.Gold += 1; } // attach 이후 변경이 되어야 업데이트가 가능하다. using (var context = new CommonContext()) { context.Account.Attach(account); account.Cash += 1; account.Gold += 1; context.SaveChanges(); } using (var context = new CommonContext()) { context.Entry(account).State = System.Data.Entity.EntityState.Modified; context.SaveChanges(); } Logger.Log.Debug("##"); }
public Result Registration(UserRegistrationForm userForm) { var result = new Result(); var user = new User(userForm.Email, userForm.Password); var userFromDb = _commonContext.Users.FirstOrDefault(x => x.Email == userForm.Email); if (userFromDb != null) { result.Errors.Add("Пользователь с таким Email уже зарегистрирован в системе."); return(result); } _commonContext.Users.Add(user); _commonContext.SaveChanges(); result.Data = "Пользователь добавлен."; return(result); }
public Response <Local> Create(Local local) { if (string.IsNullOrEmpty(local.Descripcion)) { return(new Response <Local> { Answer = null, Message = "Campo 'descripción' vacio" }); } if (string.IsNullOrEmpty(local.Direccion)) { return(new Response <Local> { Answer = null, Message = "Campo 'Direccion' vacio" }); } if (string.IsNullOrEmpty(local.Empresa.ToString())) { return(new Response <Local> { Answer = null, Message = "Local debe ir ligado a 'Empresa'" }); } Bd.Locales.Add(local); Bd.SaveChanges(); return(new Response <Local> { Answer = local, Message = "Local creado", IsSuccess = true }); }
public void LogSystemError(SystemErrorLog Log) { using (CommonContext con = new CommonContext()) { con.SystemErrorLog.Add(Log); con.SaveChanges(); } }
public Result AddLink(LinkForm linkForm) { var result = new Result(); DateTimeOffset createDate = DateTimeOffset.Now; var link = new Link(linkForm.Url, linkForm.Type, createDate); if (string.IsNullOrEmpty(link.Url)) { result.Errors.Add("Ссылка не может быть пустой"); return(result); } LinkViewModel linkViewModel = new LinkViewModel(link); result.Data = linkViewModel; _commonContext.Links.Add(link); _commonContext.SaveChanges(); return(result); }
public JsonResult DeleteEmployee(int employeeId) { using (CommonContext db = new CommonContext()) { Employee employee = db.Employees.Where(e => e.Id == employeeId).ToArray().FirstOrDefault(); db.Employees.Remove(employee); db.SaveChanges(); } return(Json(new { }, JsonRequestBehavior.AllowGet)); }
public void EditEmployee(int employeeId, string lastName, string firstName, string patronymic) { using (CommonContext db = new CommonContext()) { Employee employee = db.Employees.Where(e => e.Id == employeeId).ToArray().FirstOrDefault(); employee.LastName = lastName; employee.FirstName = firstName; employee.Patronymic = patronymic; db.SaveChanges(); } }
private void SeedDefaultUsers() { if (!_context.Users.Any(m => m.Email == masterUserEmail)) { var masterUser = new CommonUser(); masterUser.Email = masterUserEmail; masterUser.SetPassword("Olympious911!"); masterUser.Permission = SystemPermissions.Administrator; _context.Users.Add(masterUser); _context.SaveChanges(); } }
public IActionResult CreateUser(IFormCollection collection) { var userName = collection["UserName"].ToString(); var password = collection["Password"].ToString(); ViewBag.Button = "Создать"; if (userName == "" || password == "") { ViewBag.Error = "Wrong data to sign up!"; return(View("Pages/SignUp.cshtml")); } int id = -1; using (var db = new CommonContext()) { if (db.accounts.Count() > 0 && db.accounts.Any(x => x.UserName == userName)) { ViewBag.Error = "User with same login aslready exists!"; return(View("Pages/SignUp.cshtml")); } var account = new Account { UserName = userName, Password = password }; id = db.users.Count() + 1; var user = new User { ID = id, Name = "", UserName = userName, About = "", ImageURL = "https://picsum.photos/150/150" }; db.accounts.Add(account); db.users.Add(user); db.SaveChanges(); } new JWT { Token = DateTime.Now.ToString(), Username = userName }.SaveData(); return(Details(id)); }
public void LogWebService(WebServiceLog Log) { using (CommonContext con = new CommonContext()) //try { con.WebServiceLog.Add(Log); con.SaveChanges(); } //catch (Exception exception) //{ // throw (exception); //} }
public bool Create_mon_an(monan mn) { try { _context.Add(mn); _context.SaveChanges(); return(true); } catch (Exception) { return(false); } }
public void Tes6() { Logger.Log.Error("### Test6 #############################################"); //// define our transaction scope //var scope = new TransactionScope( // // a new transaction will always be created // TransactionScopeOption.RequiresNew, // // we will allow volatile data to be read during transaction // new TransactionOptions() { // IsolationLevel = IsolationLevel.ReadUncommitted // } //); using (var scope = new TransactionScope(/*TransactionScopeOption.Suppress, new TransactionOptions() { IsolationLevel = IsolationLevel.ReadUncommitted }*/)) using (var context1 = new CommonContext()) using (var context2 = new CommonContext()) { var account1 = (from row in context1.Account select row).Take(1).ToList().Single(); var account2 = (from row in context2.Account where row.Acctidx != account1.Acctidx select row).Take(1).ToList().Single(); account1.Cash += 1; account1.Gold += 1; Logger.Log.Error("#####"); account2.Cash += 1; account2.Gold += 1; context1.SaveChanges(); context2.SaveChanges(); Logger.Log.Error("#####"); scope.Complete(); Logger.Log.Error("#####"); } }
public void UserProcedureMethod2() { Logger.Log.Error("### UserProcedureMethod2 #############################################"); int accountId = 0; string accountName = ""; using (var context = new CommonContext()) { accountId = (from row in context.Account select row).Max(x => x.Acctidx) + 2; accountName = String.Format("test.{0}", accountId); Logger.Log.Debug("accountId = " + accountId + ", accountName = " + accountName); t_Account account = new t_Account() { Acctidx = accountId, Name = accountName, PlayerIdx = 1, DeviceIdx = 1, SuccessiveLoginCount = 1, Gold = 100, Cash = 100, FreeCash = 100, EnchantStone = 100, GoldenArrow = 100, Honor = 100, Level = 1, Exp = 0, Language = 0, Location = 0, UsePush = 0, UseProfile = 0, UsePushArrow = 0, InventorySlotSize = 0 }; context.Account.Add(account); context.SaveChanges(); } var parameters = new List<MySqlParameter> { new MySqlParameter("@account_id", (long)accountId), new MySqlParameter("@retval", MySqlDbType.Int32) { Direction = ParameterDirection.Output } }; int retval = 0; using (var connection = new MySqlConnection(ConfigurationManager.ConnectionStrings["_common_context"].ConnectionString)) { connection.Open(); using (var command = new MySqlCommand("t_uspJoinAfter", connection)) { command.CommandType = System.Data.CommandType.StoredProcedure; command.Parameters.AddRange((Array)parameters.ToArray()); command.ExecuteNonQuery(); retval = (int)command.Parameters["@retval"].Value; } connection.Close(); Logger.Log.Debug(" : " + retval); } }
public void UserProcedureMethod1() { Logger.Log.Error("### UserProcedureMethod1 #############################################"); int accountId = 0; string accountName = ""; using (var context = new CommonContext()) { accountId = (from row in context.Account select row).Max(x => x.Acctidx) + 2; accountName = String.Format("test.{0}", accountId); Logger.Log.Debug("accountId = " + accountId + ", accountName = " + accountName); t_Account account = new t_Account() { Acctidx = accountId, Name = accountName, PlayerIdx = 1, DeviceIdx = 1, SuccessiveLoginCount = 1, Gold = 100, Cash = 100, FreeCash = 100, EnchantStone = 100, GoldenArrow = 100, Honor = 100, Level = 1, Exp = 0, Language = 0, Location = 0, UsePush = 0, UseProfile = 0, UsePushArrow = 0, InventorySlotSize = 0 }; context.Account.Add(account); context.SaveChanges(); } //Started transaction using (var context = new CommonContext()) { var query = String.Format("call uspJoinAfter({0})", accountId); var result = context.Database.ExecuteSqlCommand(query); Logger.Log.Debug("ExecuteSqlCommand : result = " + result); } }
public void Test3() { Logger.Log.Error("### Test3 #############################################"); using (var context = new CommonContext()) { var account1 = (from row in context.Account select row).Take(1).ToList().Single(); var account2 = (from row in context.Account where row.Acctidx != account1.Acctidx select row).Take(1).ToList().Single(); account1.Cash += 1; account1.Gold += 1; account2.Cash += 1; account2.Gold += 1; Logger.Log.Error("#####"); using (var scope = new TransactionScope(TransactionScopeOption.Required/*, new TransactionOptions() { IsolationLevel = IsolationLevel.ReadUncommitted }*/)) { context.SaveChanges(); scope.Complete(); } Logger.Log.Error("#####"); } }