public int Update(HeadOffice headOffice) { try { Query = "UPDATE tbl_HeadOffice SET Name=@Name, Email=@Email,Phone=@Phone,Mobile=@Mobile,Address=@Address,Fax=@Fax,UpdateDate=GetDate() WHERE Head_Office_Id=@Id"; Command.CommandText = Query; Command.Parameters.Clear(); Command.Parameters.AddWithValue("Name", headOffice.Name); Command.Parameters.AddWithValue("Email", headOffice.Email); Command.Parameters.AddWithValue("Phone", headOffice.Phone); Command.Parameters.AddWithValue("Mobile", headOffice.Mobile); Command.Parameters.AddWithValue("Fax", headOffice.Fax); Command.Parameters.AddWithValue("Address", headOffice.Address); Command.Parameters.AddWithValue("Id", headOffice.Id); Connection.Open(); int rowAffected = Command.ExecuteNonQuery(); return(rowAffected); } finally { if (Connection != null && Connection.State != ConnectionState.Closed) { Connection.Close(); } } }
public void test_diorexportprocessor() { var hos = HeadOffice.ParseList("250, 123171; 250, 131969; 250, 137261; 250, 139245;"); DiorExportProcessor p = new DiorExportProcessor(hos); p.Run(); }
public IBusinessDocument CreateBusiness(string name, string tradingName, string webAddress, string headContactFirstName, string headContactSecondName, string headContactContactNumber, string headContactEmail, string headOfficePostCode, string headOfficeAddressLine1, string headOfficeAddressLine2, int code) { var headOffice = new HeadOffice().Setup(headOfficePostCode, headOfficeAddressLine1, headOfficeAddressLine2); var headContact = new HeadContact().Setup(headContactFirstName, headContactSecondName, headContactContactNumber, headContactEmail); return(new Domain.BusinessDocument().Setup(name, tradingName, webAddress, headOffice, headContact, code)); }
public void TestRepository() { SessionFactory.Init("Server=(localdb)\\mssqllocaldb;Database=DddInPractice;Trusted_Connection=True;"); SnackMachineRepository repository = new SnackMachineRepository(); SnackMachine snackMachine = repository.GetById(1); HeadOfficeInstance.Init(); HeadOffice headOffice = HeadOfficeInstance.Instance; }
public string Update(HeadOffice headOffice) { int rowAfftected = headOfficeGateway.Update(headOffice); if (rowAfftected > 0) { return("Item Updated"); } return("Update Failed"); }
public String Save(HeadOffice headOffice) { int rowAfftected = headOfficeGateway.Save(headOffice); if (rowAfftected > 0) { return("Item Saved"); } return("Save Failed"); }
public void InsertTest() { _repository.Add(headOfficeStub1); _repository.SaveChanges(); //Check whether on database or not headOffice = _repository.GetById(headOfficeStub1.Id); Assert.IsNotNull(headOffice, "Data Head Office Baru Berhasil Terbuat"); //Delete so this method can be used again _repository.Delete(headOfficeStub1); _repository.SaveChanges(); }
private void LoadCashToAtm(AtmDto atmDto) { Atm atm = _atmRepository.GetById(atmDto.Id); if (atm == null) return; HeadOffice.LoadCashToAtm(atm); _atmRepository.Save(atm); _headOfficeRepository.Save(HeadOffice); RefreshAll(); }
private void UnloadCash(SnackMachineDto snackMachineDto) { var snackMachine = _snackMachineRepository.GetById(snackMachineDto.Id); if (snackMachine == null) return; HeadOffice.UnloadCashFromSnackMachine(snackMachine); _snackMachineRepository.Save(snackMachine); _headOfficeRepository.Save(HeadOffice); RefreshAll(); }
public void DeleteHeadOfficeTest() { //Add first to make data dummy _repository.Add(headOfficeStub1); _repository.SaveChanges(); //Delete _repository.Delete(headOfficeStub1); _repository.SaveChanges(); //make sure wheter data is no longer in database headOffice = _repository.GetById(headOfficeStub1.Id); Assert.IsNull(headOffice, "Head Office Terhapus"); }
public void GetByIdHeadOfficeTest() { //Add data _repository.Add(headOfficeStub1); _repository.SaveChanges(); //Test case HeadOffice headoffice = _repository.GetById(headOfficeStub1.Id); Assert.IsNotNull(headoffice); //Delete data _repository.Delete(headOfficeStub1); _repository.SaveChanges(); }
public void UpdateHeadOfficeTest() { //precondition _repository.Add(headOfficeInsertStub1); _repository.SaveChanges(); _repository.Update(headOfficeUpdateStub1); _repository.SaveChanges(); headOffice = _repository.GetById(headOfficeUpdateStub1.Id); Assert.AreEqual(headOffice.Address, headOfficeUpdateStub1.Address); //delete data _repository.Delete(headOfficeUpdateStub1); _repository.SaveChanges(); }
public void Test() { SessionFactory.Init(@"Data Source=(LocalDB)\MSSQLLocalDB;Initial Catalog=DDDInPractice;Integrated Security=True"); HeadOfficeInstance.Init(); HeadOffice office = HeadOfficeInstance.Instance; //var repository = new SnackMachineRepository(); //SnackMachine snackMachine = repository.GetById(1); //snackMachine.InsertMoney(Money.Dollar); //snackMachine.InsertMoney(Money.Dollar); //snackMachine.InsertMoney(Money.Dollar); //snackMachine.BuySnack(1); //repository.Save(snackMachine); }
private void DiorFileSystemWatcher_Created(object sender, FileSystemEventArgs e) { Task.Factory.StartNew(() => { var hostr = ConfigurationManager.AppSettings["DiorHOs"]; var hos = HeadOffice.ParseList(hostr); var proc = new DiorExportProcessor(hos); proc.Run(); }, TaskCreationOptions.LongRunning); Thread.Sleep(1000); if (File.Exists(e.FullPath)) { File.Delete(e.FullPath); } }
public HeadOfficeServiceResponse Update(HeadOfficeDomain headOffice) { HeadOfficeServiceResponse response = new HeadOfficeServiceResponse(); if (validateIsNotExist(headOffice.Id)) { response.Messages.Add(new Message("Data is not in Database")); } else { headOfficeEntity = new HeadOffice(); MergeExtension.Merge(headOfficeEntity, headOffice); _headOfficeRepository.Update(headOfficeEntity); _headOfficeRepository.SaveChanges(); } return(response); }
public HeadOfficeServiceResponse GetHeadOfficeById(Guid id) { HeadOfficeServiceResponse response = new HeadOfficeServiceResponse(); HeadOffice headOffice = _headOfficeRepository.GetById(id); if (headOffice == null) { response.Messages.Add(new Message("Data is not in Database")); } else { HeadOfficeDomain headOfficeDomain = new HeadOfficeDomain(); MergeExtension.Merge(headOfficeDomain, headOffice); response.HeadOfficeDomain = headOfficeDomain; } return(response); }
public int Save(HeadOffice headOffice) { try { Query = "Insert into tbl_HeadOffice (Name,Email,Phone,Mobile,Address,Fax,CreateDate) values ('" + headOffice.Name + "','" + headOffice.Email + "','" + headOffice.Phone + "','" + headOffice.Mobile + "','" + headOffice.Address + "','" + headOffice.Fax + "',GETDATE()) "; Command.CommandText = Query; Connection.Open(); int rowAfftected = Command.ExecuteNonQuery(); return(rowAfftected); } finally { if (Connection != null && Connection.State != ConnectionState.Closed) { Connection.Close(); } } }
public List <HeadOffice> GetAllHeadOffice() { try { Query = "Select * from tbl_HeadOffice"; Connection.Open(); Command.CommandText = Query; Reader = Command.ExecuteReader(); List <HeadOffice> headOffices = new List <HeadOffice>(); while (Reader.Read()) { HeadOffice headOffice = new HeadOffice() { Id = (int)Reader["Head_Office_Id"], Name = Reader["Name"].ToString(), Address = Reader["Address"].ToString(), // Phone = Reader["Phone"].ToString(), Email = Reader["Email"].ToString(), Mobile = Reader["Mobile"].ToString() // Fax = Reader["Fax"].ToString() }; headOffices.Add(headOffice); } Reader.Close(); return(headOffices); } finally { if (Connection != null && Connection.State != ConnectionState.Closed) { Connection.Close(); } } }
public HeadOffice GetById(int id) { try { Query = "SELECT * FROM tbl_Headoffice WHERE Head_Office_Id = @Id"; Command.CommandText = Query; Command.Parameters.Clear(); Command.Parameters.AddWithValue("Id", id); Connection.Open(); Reader = Command.ExecuteReader(); HeadOffice headOffice = null; if (Reader.HasRows) { Reader.Read(); headOffice = new HeadOffice() { Id = (int)Reader["Head_Office_Id"], Name = Reader["Name"].ToString(), Address = Reader["Address"].ToString(), Phone = Reader["Phone"].ToString(), Mobile = Reader["Mobile"].ToString(), Email = Reader["Email"].ToString(), Fax = Reader["Fax"].ToString() }; } Reader.Close(); return(headOffice); } finally { if (Connection != null && Connection.State != ConnectionState.Closed) { Connection.Close(); } } }
public void StartClient() { try { User userNew = null; Menu menu = null; logger.Log(Status.Info, "Finished generating books"); //books.ForEach(book => Console.WriteLine(book)); byte[] bytes = new byte[1024]; bool isActive = true; while (isActive) { var userOption = ShowFirstMenu(); switch (userOption) { case AuthenticationOption.Register: userNew = Register(); break; case AuthenticationOption.Login: userNew = Login(); break; case AuthenticationOption.Invalid: Console.WriteLine("Invalid Option"); break; default: break; } if (userOption != AuthenticationOption.Invalid) { KeyValuePair <int, User> data = new KeyValuePair <int, User>((int)userOption, userNew); string serializedObject = JToken.FromObject(data).ToString(); byte[] msg = Encoding.ASCII.GetBytes(serializedObject); int bytesSent = sender.Send(msg); int bytesRec = sender.Receive(bytes); string receivedMessage = Encoding.ASCII.GetString(bytes, 0, bytesRec); try { userNew = JToken.Parse(receivedMessage).ToObject <User>(); isActive = false; menu = new Menu(userNew); Console.WriteLine("Welcome"); } catch { Console.WriteLine(receivedMessage); } } } if (userNew.Role == Role.User) { HeadOffice headOffice = new HeadOffice("Ofiice", "Head", DateTime.Now, null, Gender.Female); Librarian librarian = new Librarian("Librarian", "Last", DateTime.Now, headOffice, Gender.Female); userNew.Supervisor = librarian; Console.Clear(); menu.UpdateState(EUserOption.Login); UserMenu(userNew, menu); } else { Console.Clear(); AdminMenu(); } // Release the socket. sender.Shutdown(SocketShutdown.Both); sender.Close(); } catch (Exception e) { Console.WriteLine(e.ToString()); } }
public void UpdateNullHeadOfficeTest() { _repository.Update(headOfficeUpdateStub1); _repository.SaveChanges(); headOffice = _repository.GetById(headOfficeUpdateStub1.Id); }
public ActionResult AddUser() { var ctx1 = PTFContext.Current; var ctx2 = PTFReportsContext.Current; var model = Session.Get <UserModel>(Strings.CachedMODELUserDetails, new UserModel()); TryUpdateModel(model); switch (model.CurrentStep) { case null: case "": case "FormStart": ViewData["CountryList"] = new SelectList(ctx1.ISO_ptf .OrderBy(iso => iso.iso_country), "iso_number", "iso_country", null); break; case "CountryList": model.CountryID = Request.Parse <int>("CountryList", model.CountryID); ViewData["CompanyList"] = new SelectList(ctx1.HeadOffices .Where(ho => ho.ho_iso_id == model.CountryID) .OrderBy(ho => ho.ho_name), "ho_id", "ho_name", null); break; case "CompanyList": model.CompanyID = Request.Parse <int>("CompanyList", model.CompanyID); ViewData["BranchList"] = new SelectList(ctx1.Branches .Where(br => br.br_iso_id == model.CountryID && br.br_ho_id == model.CompanyID && (br.br_active == "Y" || !br.br_date_left.HasValue)) .OrderBy(br => br.br_name), "br_id", "FullName", null); break; case "BranchList": model.BranchID = Request.Parse <int>("BranchList", model.BranchID); ViewData["UserTypeList"] = new SelectList(UserType.Normal.ToDict <UserType>(), "Key", "Value", model.UserTypeID); ViewData["LanguageList"] = new SelectList(eLanguage.English.ToDict <eLanguage>(), "Key", "Value", model.LanguageID); break; case "UserTypeList": model.UserTypeID = Request.Parse <int>("UserTypeList", model.UserTypeID); model.LanguageID = Request.Parse <int>("LanguageList", model.LanguageID); model.Language = model.LanguageID.GetEnumName <eLanguage>(); model.DefaultPass = string.IsNullOrEmpty(model.DefaultPass) ? new Random().GenerateString(DEFPASSLEN) : model.DefaultPass; model.CurrentStep = "FormSubmit"; break; case "FormSubmit": { if (IsValidPostBack("Name")) { return(RunSafe(() => { if (model.UserID == 0) { //Add var user = (UserDetail)model; user.Ud_firstLogin = true; ctx2.AddToUserDetails(user); //TODO: Remove var root = ctx2.Folders.FirstOrDefault(f => !f.ParentID.HasValue); if (root != null) { user.Folders.Add(root); } } else { //Update var pass = model.DefaultPass.Encript(); var user = ctx2.UserDetails.First(u => u.Ud_id == model.UserID); user.Ud_loginName = model.Login; user.Ud_firstName = model.Name; user.Ud_lastName = model.Surname; user.Ud_email = model.Email; user.Ud_userType = model.UserTypeID; user.Ud_password = pass; user.Ud_salt = model.Salt ?? ""; user.Ud_iso_id = model.CountryID; user.Ud_ho_id = model.CompanyID; user.Ud_br_id = model.BranchID; user.Ud_languageId = model.LanguageID; } ctx2.SaveChanges(); Session.Remove(Strings.CachedMODELUserDetails); })); } } break; } model.Country = ISO_ptf.GetNameByID(model.CountryID); model.Company = HeadOffice.GetNameByID(model.CountryID, model.CompanyID); model.Branch = Branch.GetNameByID(model.CountryID, model.CompanyID, model.BranchID); model.UserType = ((UserType)model.UserTypeID).ToString(); return(View(model)); }
private void ShowLongParameterForm(ReportParametersModel model, Report report, ParamObj data) { var user = Session[Strings.USER].Cast <UserDetail>(); var repository = Session.Get <TagRepository>(Strings.TagRepository, new TagRepository()); var ctx1 = PTFContext.Current; var ctx2 = PTFReportsContext.Current; if (model.CurrentStep == "IsoID") { model.CurrentStep = "CompanyID"; } else if (model.CurrentStep == "CompanyID") { model.CurrentStep = "RetailerID"; } else if (model.CurrentStep == "RetailerID") { model.CurrentStep = "FormSubmit"; } else if (model.CurrentStep == "FormSubmit") { model.CurrentStep = null; } switch (model.CurrentStep) { case "": case null: { goto case "IsoID"; } case "IsoID": { model.CurrentStep = "IsoID"; model.SkipCountry = true; model.CountryID = user.Ud_iso_id; goto case "CompanyID"; //always get user country var list = new List <ISO_ptf>(); list.Add(ISO_ptf.GetUserDefault(user)); ViewData[ParamMapping.IsoID.ToString()] = new SelectList(list.OrderBy(c => c.iso_country), "iso_number", "iso_country", null); } break; case "CompanyID": { model.CurrentStep = "CompanyID"; model.CompanyID = user.Ud_ho_id; model.Country = ISO_ptf.GetNameByID(model.CountryID); var list = new List <HeadOffice>(); //user permissions var permissions = ctx2.Permissions.Where(p => p.UserID == user.Ud_id && p.IsoID == model.CountryID); foreach (var gp in permissions.GroupBy(c => c.HoID)) { var p = gp.First(); list.Add(ctx1.HeadOffices.FirstOrDefault( ho => ho.ho_iso_id == p.IsoID && ho.ho_id == p.HoID)); } model.SkipCompany = list.Count < 2; //get user's company if (list.Count == 0) { model.CompanyID = user.Ud_ho_id; goto case "RetailerID"; } ViewData[ParamMapping.CompanyID.ToString()] = new SelectList(list.OrderBy(ho => ho.ho_name), "ho_id", "ho_name", null); } break; case "RetailerID": { model.CurrentStep = "RetailerID"; model.CompanyID = data.CompanyID.Parse(user.Ud_ho_id); model.Company = HeadOffice.GetNameByID(user.Ud_iso_id, model.CompanyID); // retailers var list = new List <Branch>(); //user permissions var permissions = ctx2.Permissions.Where(p => p.UserID == user.Ud_id && p.IsoID == user.Ud_iso_id && p.HoID == model.CompanyID); repository.Clear(); foreach (Permission p in permissions) { var branch = ctx1.Branches.FirstOrDefault( br => br.br_iso_id == p.IsoID && br.br_ho_id == p.HoID && br.br_id == p.RetailerID); list.Add(branch); repository.SetTag(branch); } //get user's retailer if (list.Count == 0) { var branch = Branch.GetUserDefault(user); list.Add(branch); repository.SetTag(branch); } ViewData[ParamMapping.RetailerID.ToString()] = new MultiSelectList(list.OrderBy(br => br.FullName2), "br_id", "FullName2", null); } break; } }
public JsonResult GeHeadOfficeById(int id) { HeadOffice headOffice = headOfficeManager.GetById(id); return(Json(headOffice, JsonRequestBehavior.AllowGet)); }
public static void Init(IHeadOfficeRepository repository) { Instance = repository.GetById(HeadOfficeId); }
public static void Init() { Instance = new HeadOfficeRepository().GetById(Id); }
static void Main(string[] args) { var bookGenerator = BookGenerator.Instance; string outputPath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); var logger = Logger.Instance; logger.AddObservers( new List <ILoggingService>() { new ConsoleLogger(), new FileLogger(new FileInfo(Path.Combine(outputPath, "logs.txt"))) } ); var books = bookGenerator.GenerateBooks(); logger.Log(Status.Info, "Finished generating books"); //books.ForEach(book => Console.WriteLine(book)); Library.Books = books; var databaseConnection = DatabaseConnection.Instance; databaseConnection.OpenConnection(); var userRepository = new UserRepository <User>(databaseConnection.Connetion); User userNew = null; Menu menu = null; while (true) { int op = ShowFirstMenu(); switch (op) { case 1: userNew = Register(); userRepository.Add(userNew); menu = new Menu(userNew); break; case 2: userNew = Login(userRepository); menu = new Menu(userNew); break; case -1: break; } if (op != -1) { if (userNew != null) { Console.WriteLine("Welcome"); break; } else { Console.WriteLine("Wrong username or password"); } } } if (userNew.Role.Equals("USER")) { HeadOffice headOffice = new HeadOffice("Ofiice", "Head", DateTime.Now, null, Utils.Gender.Female); Librarian librarian = new Librarian("Librarian", "Last", DateTime.Now, headOffice, Utils.Gender.Female); userNew.Supervisor = librarian; menu.UpdateState(EUserOption.Login); Console.Clear(); UserMenu(userNew, menu); } else { AdminMenu(); } //HeadOffice headOffice = new HeadOffice("Ofiice", "Head", DateTime.Now, null, Utils.Gender.Female); //Librarian librarian = new Librarian("Librarian", "Last", DateTime.Now, headOffice, Utils.Gender.Female); //User user = new User("First", "Last", DateTime.Now, librarian, Utils.Gender.Male); //user.Username = "******"; //user.Password = "******"; //BorrowRequest borrowRequest = new BorrowRequest(DateTime.Now, new DateTime(2020, 6, 11), books.ElementAt(0)); //user.ApplyRequest(borrowRequest); //userRepository.Add(user); //userRepository.Add(user); //var allUsers = userRepository.SelectAll(); //foreach(var queridUser in allUsers) //{ // Console.WriteLine(queridUser.FirstName + " " + queridUser.LastName); //} }
public static void Init() { var repository = new HeadOfficeRepository(); Instance = repository.GetById(HeadOfficeId); }
public Task <bool> UpdateOfficeAsync(HeadOffice office, Guid businessId) => _httpExecutor.SendRequestAsync(() => Client.PostAsync("update-office", JsonMessage.CreateJsonMessage(new { BusinessId = businessId, office.PostCode, office.AddressLine1, office.AddressLine2 })), "Business contact updated succesfully");