Пример #1
0
        public Contractor Update(int ID, string PrefixName, string LastName, string FirstName, string MiddleName,
                                 string Country, string Region, string District, string City, string Street, string Building, string Flat,
                                 string Phone, string MobilePhone, string Email, string Site, DateTime?Birthdate, bool?Sex, bool?Person,
                                 List <int> ContractorTypes)
        {
            Contractor sr = (from a in context.Contractors
                             where a.ID == ID
                             select a).FirstOrDefault();

            sr.LastName = LastName;



            sr.FirstName   = FirstName;
            sr.MiddleName  = MiddleName;
            sr.Country     = Country;
            sr.District    = District;
            sr.Region      = Region;
            sr.City        = City;
            sr.Street      = Street;
            sr.Building    = Building;
            sr.Flat        = Flat;
            sr.Phone       = Phone;
            sr.MobilePhone = MobilePhone;
            sr.EMail       = Email;
            sr.Site        = Site;
            sr.Birthdate   = Birthdate;
            sr.Sex         = Sex;
            sr.Person      = Person;
            sr.PrefixName  = PrefixName;

            foreach (int i in ContractorTypes)
            {
                var check = (from a in context.ContractorContractorTypes
                             where a.ContractorID == ID & a.ContractorTypeID == i
                             select a).FirstOrDefault();
                //видаляємо невідмічені
                IEnumerable <ContractorContractorType> forDelete = from a in context.ContractorContractorTypes
                                                                   where a.ContractorID == ID& ContractorTypes.Contains(a.ContractorTypeID) == false
                                                                   select a;

                foreach (ContractorContractorType t in forDelete)
                {
                    context.ContractorContractorTypes.DeleteObject(t);
                }

                if (check == null)
                {
                    ContractorContractorType ct = new ContractorContractorType();
                    ct.ContractorTypeID = i;
                    sr.ContractorContractorTypes.Add(ct);
                }
            }

            return(sr);
        }
Пример #2
0
        public Contractor Create(string PrefixName, string LastName, string FirstName, string MiddleName,
                                 string Country, string Region, string District, string City, string Street, string Building, string Flat,
                                 string Phone, string MobilePhone, string Email, string Site, DateTime?Birthdate, bool?Sex, bool?Person,
                                 List <int> ContractorTypes)
        {
            Contractor sr = Contractor.CreateContractor(1, LastName);

            sr.FirstName   = FirstName;
            sr.MiddleName  = MiddleName;
            sr.Country     = Country;
            sr.City        = City;
            sr.Region      = Region;
            sr.District    = District;
            sr.Street      = Street;
            sr.Building    = Building;
            sr.Flat        = Flat;
            sr.Phone       = Phone;
            sr.MobilePhone = MobilePhone;
            sr.EMail       = Email;
            sr.Site        = Site;
            sr.Birthdate   = Birthdate;
            sr.Sex         = Sex;
            sr.Person      = Person;
            sr.PrefixName  = PrefixName;
            context.AddToContractors(sr);


            foreach (int a in ContractorTypes)
            {
                ContractorContractorType ct = new ContractorContractorType();
                ct.ContractorTypeID = a;
                sr.ContractorContractorTypes.Add(ct);
            }

            return(sr);
        }