コード例 #1
0
        /// <summary>
        ///  Добавление нового менеджера в БД.
        /// </summary>
        public void Save()
        {
            try
            {
                var IsSaved = objManagerService.Add(CurrentManager);
                LoadData();

                if (IsSaved)
                {
                    Message = "Менеджер успешно добавлен !";
                }
                else
                {
                    Message = "Ошибка добавления !";
                }
            }
            catch (Exception ex)
            {
                Message = ex.Message;
            }
        }
コード例 #2
0
        internal static void StartData()
        {
            //add contact "6acb9fb3-9213-49cd-abda-f9785a658d12"
            //var contact = new BLL.Contact();
            //contact.Id = Guid.Parse("6acb9fb3-9213-49cd-abda-f9785a658d12");
            //contact.FirstName = "Гайдель";
            //contact.LastName = "Ирина";
            ////AutoMapper DAL
            //var contactDAL = MappingService.MappingForDALEntity(contactService, contact);
            //contactService.Add(contactDAL);
            //SaveChangesWithException(contactService, "контакта");

            var contact = new BLL.Contact();

            contact.Id        = Guid.Parse("6acb9fb3-9213-49cd-abda-f9785a658d22");
            contact.FirstName = "Гайдель";
            contact.LastName  = "Лев";
            //AutoMapper DAL
            var contactDAL = MappingService.MappingForDALEntity(contactService, contact);

            contactService.Add(contactDAL);
            SaveChangesWithException(contactService, "контакта");

            //add manager "6acb9fb3-9213-49cd-abda-f9785a658d88"
            //80AB7036-5D4A-11E6-9903-0050569977A1
            //var manager = new BLL.Manager();
            //manager.Id = Guid.Parse("80AB7036-5D4A-11E6-9903-0050569977A1");
            //manager.ContactId = contact.Id;
            ////AutoMapper DAL
            //var managerDAL = MappingService.MappingForDALEntity(managerService, manager);
            //managerService.Add(managerDAL);
            //SaveChangesWithException(managerService, "менеджера");
            var manager = new BLL.Manager();

            //manager.Id = Guid.Parse("80AB7036-5D4A-11E6-9903-005056997722");
            manager.Id        = Guid.Parse("80AB7036-5D4A-11E6-9903-0050569977A1");
            manager.ContactId = contact.Id;
            //AutoMapper DAL
            var managerDAL = MappingService.MappingForDALEntity(managerService, manager);

            managerService.Add(managerDAL);
            SaveChangesWithException(managerService, "менеджера");

            //add client 6acb9fb3-9213-49cd-abda-f9785a658d55
            //var client = new BLL.Client();
            //client.Id = Guid.Parse("6acb9fb3-9213-49cd-abda-f9785a658d55");
            //client.ContactId = contact.Id;
            ////AutoMapper DAL
            //var clientDAL = MappingService.MappingForDALEntity(clientService, client);
            //clientService.Add(clientDAL);
            //SaveChangesWithException(clientService, "клиента");

            //var client = new BLL.Client();
            //client.Id = Guid.Parse("6acb9fb3-9213-49cd-abda-f9785a658d22");
            //client.ContactId = contact.Id;
            //client.Name = "Haidzel Iryna Ivanovna";
            ////AutoMapper DAL
            //var clientDAL = MappingService.MappingForDALEntity(clientService, client);
            //clientService.Add(clientDAL);
            //SaveChangesWithException(clientService, "клиента");

            //add product
            //var product = new BLL.Product();
            //product.Id = Guid.Parse("89a5c4a4-6d02-412f-bb58-55a09f8afc7d");
            ////AutoMapper DAL
            //var productDAL = MappingService.MappingForDALEntity(productService, product);
            //productService.Add(productDAL);
            //SaveChangesWithException(productService, "продукта");

            //var product = new BLL.Product();
            //product.Id = Guid.Parse("89a5c4a4-6d02-412f-bb58-55a09f8afc22");
            //product.Name = "boots";
            ////AutoMapper DAL
            //var productDAL = MappingService.MappingForDALEntity(productService, product);
            //productService.Add(productDAL);
            //SaveChangesWithException(productService, "продукта");
        }
コード例 #3
0
        private void BtnAdd_Click(object sender, EventArgs e)//add the new manager
        {
            //check if the manager information is null
            if (TxtName.Text == string.Empty || TxtSurname.Text == string.Empty || TxtPhone.Text == string.Empty || CmbPosition.Text == string.Empty || TxtUsername.Text == string.Empty || TxtPassword.Text == string.Empty)
            {
                MessageBox.Show("Managers information can't be null");
                return;
            }
            //check if the phone  contains digit
            if (!isDigit(TxtPhone.Text))
            {
                MessageBox.Show("phone number can not contain letter");
                return;
            }

            //check if the Name  contains letter
            if (!Regex.IsMatch(TxtName.Text, @"^[a-zA-Z\s]*$"))
            {
                MessageBox.Show("the name can not contain digit");
                return;
            }
            //check if the Surname contains letter
            if (!Regex.IsMatch(TxtSurname.Text, @"^[a-zA-Z\s]*$"))
            {
                MessageBox.Show("the Surname can not contain digit");
                return;
            }
            //check if the given manager is already exist
            foreach (Manager item in _managerService.Managers())
            {
                if (item.isActive == true)
                {
                    if (item.Name == TxtName.Text &&
                        item.Phone == TxtPhone.Text &&
                        item.Surname == TxtSurname.Text
                        )
                    {
                        MessageBox.Show("such manager is already exists");
                        return;
                    }
                }
            }
            //convert comboitem to boolean type
            bool IsAdminOrNot = false;

            if (CmbPosition.SelectedIndex == 0)
            {
                IsAdminOrNot = true;
            }
            Manager manager = new Manager()//manager to adding
            {
                Name     = TxtName.Text,
                Surname  = TxtSurname.Text,
                Phone    = TxtPhone.Text,
                IsAdmin  = IsAdminOrNot,
                Username = TxtUsername.Text,
                Password = Encrypt(TxtPassword.Text),
                isActive = true
            };

            _managerService.Add(manager);
            DgvManagers.Rows.Add(manager.Id, manager.Name, manager.Surname, manager.Phone, manager.IsAdmin);
            ResetSearch();
            Reset();
        }