public bool AddManager(UserType composite) { var tables = new LinqWorkerDataContext(); if (tables.Users.All(x => x.Login != composite.Login)) { string type="user", message=string.Empty; var manager = new Users() { Fio = composite.Fio, Login = composite.Login, Password = composite.Password }; try { String command = String.Format( "INSERT INTO dbo.Users(Fio,Login,Password) VALUES(\'{0}\',\'{1}\',\'{2}\')", manager.Fio, manager.Login, manager.Password ); tables.ExecuteCommand(command); message = "Добавлен новый пользователь : " + composite.Fio; return true; } catch (Exception ex) { Console.WriteLine(ex.Message); message = "Ошибка при добавление пользователя : " + composite.Fio; type = "system"; return false; } finally { AddLog(type, message, DateTime.Now.ToString("MM/dd/yyyy HH:mm")); } } return false; }
public bool AddOrder(OrderType composite) { var tables = new LinqWorkerDataContext(); if (tables.Orders.All(x => x.Date != composite.Date )) { string type = "user", message = string.Empty; var order = new Orders { UserId = composite.UserId, Article = composite.Article, Date = composite.Date, Comment = composite.Comment, ItemCount = composite.ItemCount, ItemId = composite.ItemId }; try { String command = String.Format( "INSERT INTO dbo.Orders(Article,UserId,Date,Comment,Itemid,ItemCount) VALUES(\'{0}\',\'{1}\',\'{2}\',\'{3}\',\'{4}\',\'{5}\')", order.Article, order.UserId, order.Date, order.Comment, order.ItemId, order.ItemCount ); tables.ExecuteCommand(command); message = "Добавлена новая заявка : " + order.Article; //tables.Orders.Context.SubmitChanges(); return true; } catch (Exception ex) { message = "Ошибка при добавление заявки : " + order.Article; type = "system"; Console.WriteLine(ex.Message); return false; } finally { AddLog(type, message, DateTime.Now.ToString("MM/dd/yyyy HH:mm")); } } return false; }
private void AddLog(string type, string message, string datetime) { var tables = new LinqWorkerDataContext(); try { String command = String.Format( "INSERT INTO dbo.Log(Type,Message,Date) VALUES(\'{0}\',\'{1}\',\'{2}\')", type, message, datetime); tables.ExecuteCommand(command); //tables.Orders.Context.SubmitChanges(); } catch (Exception ex) { Console.WriteLine(ex.Message); } }