Esempio n. 1
0
        protected override void OnSaveToolBarItem()
        {
            ReadData(_activeUser);
            if (!string.IsNullOrEmpty(_activeUser.Password))
            {
                if (_activeUser.Id > 0)
                {
                    using (var dbContext = new FarnahadManufacturingDbContext())
                    {
                        var userInDb = dbContext.Users
                                       .Include(item => item.LocationGroupMembers)
                                       .First(item => item.Id == _activeUser.Id);

                        userInDb.FirstName    = _activeUser.FirstName;
                        userInDb.LastName     = _activeUser.LastName;
                        userInDb.UserName     = _activeUser.UserName;
                        userInDb.Email        = _activeUser.Email;
                        userInDb.PhoneNumber  = _activeUser.PhoneNumber;
                        userInDb.Initial      = _activeUser.Initial;
                        userInDb.IsActive     = _activeUser.IsActive;
                        userInDb.PasswordSalt = _activeUser.PasswordSalt;
                        userInDb.Password     = _activeUser.Password;

                        userInDb.LocationGroupMembers.Clear();
                        foreach (var locationGroup in _activeUser.LocationGroupMembers)
                        {
                            var locationGroupInDb = dbContext.LocationGroups.Find(locationGroup.Id);
                            userInDb.LocationGroupMembers.Add(locationGroupInDb);
                        }

                        dbContext.SaveChanges();

                        IsEditing();
                    }
                }
                else
                {
                    _activeUser.CreatedDateTime = ApplicationSessionService.GetNowDateTime();
                    using (var dbContext = new FarnahadManufacturingDbContext())
                    {
                        dbContext.Users.Add(_activeUser);
                        foreach (var locationGroup in _activeUser.LocationGroupMembers)
                        {
                            locationGroup.CreatedByUserId = ApplicationSessionService.GetActiveUserId();
                            locationGroup.CreatedDateTime = ApplicationSessionService.GetNowDateTime();
                        }
                        dbContext.SaveChanges();

                        OnAddToolBarItem();
                    }
                }
            }
            else
            {
                MessageBox.Show("رمز عبور باید تنظیم شود");
            }

            MessageBoxService.SaveConfirmation(_activeUser.UserName);
            LoadSearchGridControl();
        }
        protected override void OnSaveToolBarItem()
        {
            ReadData(_activeProvince);
            using (var dbContext = new FarnahadManufacturingDbContext())
            {
                if (_activeProvince.Id > 0)
                {
                    dbContext.Entry(_activeProvince).State = EntityState.Modified;
                    dbContext.SaveChanges();

                    IsEditing();
                }
                else
                {
                    _activeProvince.CreatedByUserId = ApplicationSessionService.GetActiveUserId();
                    _activeProvince.CreatedDateTime = ApplicationSessionService.GetNowDateTime();
                    dbContext.Provinces.Add(_activeProvince);
                    dbContext.SaveChanges();

                    OnAddToolBarItem();
                }
            }

            MessageBoxService.SaveConfirmation(_activeProvince.Title);
            LoadSearchGridControl();
        }
        protected override void OnSaveToolBarItem()
        {
            ReadData(_activeCarrier);
            if (_activeCarrier.Id > 0)
            {
                using (var dbContext = new FarnahadManufacturingDbContext())
                {
                    var carrier         = dbContext.Carriers.Find(_activeCarrier.Id);
                    var carrierServices = dbContext.CarrierServices
                                          .Where(item => item.CarrierId == carrier.Id);

                    foreach (var carrierService in carrierServices)
                    {
                        var tempCarrier = _carrierServices.FirstOrDefault(item => item.Id == carrierService.Id);

                        if (tempCarrier == null)
                        {
                            dbContext.CarrierServices.Remove(carrierService);
                        }
                        else
                        {
                            carrierService.Title = tempCarrier.Title;
                            carrierService.Code  = tempCarrier.Code;
                            dbContext.Entry(carrierService).State = EntityState.Modified;
                        }
                    }

                    foreach (var carrierService in _carrierServices.Where(item => item.Id <= 0))
                    {
                        carrierService.Carrier = carrier;
                        dbContext.CarrierServices.Add(carrierService);
                    }

                    carrier.Title       = _activeCarrier.Title;
                    carrier.Scac        = _activeCarrier.Scac;
                    carrier.Description = _activeCarrier.Description;
                    carrier.IsActive    = _activeCarrier.IsActive;
                    dbContext.SaveChanges();

                    IsEditing();
                }
            }
            else
            {
                _activeCarrier.CreatedByUserId = ApplicationSessionService.GetActiveUserId();
                _activeCarrier.CreatedDateTime = ApplicationSessionService.GetNowDateTime();
                using (var dbContext = new FarnahadManufacturingDbContext())
                {
                    _activeCarrier.CarrierServices.AddRange(_carrierServices);
                    dbContext.Carriers.Add(_activeCarrier);
                    dbContext.SaveChanges();
                }

                OnAddToolBarItem();
            }

            MessageBoxService.SaveConfirmation(_activeCarrier.Title);
            LoadSearchGridControl();
        }
        protected override void OnSaveToolBarItem()
        {
            ReadData(_activeLocationGroup);
            if (_activeLocationGroup.Id > 0)
            {
                using (var dbContext = new FarnahadManufacturingDbContext())
                {
                    var locationGroupInDb = dbContext.LocationGroups
                                            .Include(item => item.Users)
                                            .First(item => item.Id == _activeLocationGroup.Id);
                    locationGroupInDb.Title      = _activeLocationGroup.Title;
                    locationGroupInDb.CategoryId = _activeLocationGroup.CategoryId;
                    locationGroupInDb.IsActive   = _activeLocationGroup.IsActive;

                    locationGroupInDb.Users.Clear();
                    foreach (var user in _activeLocationGroup.Users)
                    {
                        var userInDb = dbContext.Users.Find(user.Id);
                        locationGroupInDb.Users.Add(userInDb);
                    }

                    dbContext.SaveChanges();

                    IsEditing();
                }
            }
            else
            {
                _activeLocationGroup.CreatedByUserId = ApplicationSessionService.GetActiveUserId();
                _activeLocationGroup.CreatedDateTime = ApplicationSessionService.GetNowDateTime();
                using (var dbContext = new FarnahadManufacturingDbContext())
                {
                    foreach (var user in _activeLocationGroup.Users)
                    {
                        dbContext.Users.Attach(user);
                    }
                    dbContext.LocationGroups.Add(_activeLocationGroup);
                    dbContext.SaveChanges();
                }

                OnAddToolBarItem();
            }

            MessageBoxService.SaveConfirmation(_activeLocationGroup.Title);
            LoadSearchGridControl();
        }
        protected override void OnSaveToolBarItem()
        {
            ReadData(_activeUom);
            using (var dbContext = new FarnahadManufacturingDbContext())
            {
                bool isSaved = true;
                if (_activeUom.Id > 0)
                {
                    var activeUomInDb = dbContext.Uoms.First(item => item.Id == _activeUom.Id);
                    if (activeUomInDb.ReadOnly)
                    {
                        MessageBoxService.CannotEditPrompt(_activeUom.Title);
                        isSaved = false;
                    }
                    else
                    {
                        activeUomInDb.Title        = _activeUom.Title;
                        activeUomInDb.Abbreviation = _activeUom.Abbreviation;
                        activeUomInDb.ReadOnly     = _activeUom.ReadOnly;
                        activeUomInDb.Conversion   = _activeUom.Conversion;
                        activeUomInDb.Description  = _activeUom.Description;
                        activeUomInDb.IsActive     = _activeUom.IsActive;
                        activeUomInDb.UomType      = _activeUom.UomType;
                        dbContext.SaveChanges();

                        IsEditing();
                    }
                }
                else
                {
                    _activeUom.CreatedByUserId = ApplicationSessionService.GetActiveUserId();
                    _activeUom.CreatedDateTime = ApplicationSessionService.GetNowDateTime();
                    dbContext.Uoms.Add(_activeUom);
                    dbContext.SaveChanges();

                    OnAddToolBarItem();
                }

                if (isSaved)
                {
                    MessageBoxService.SaveConfirmation(_activeUom.Title);
                    LoadSearchGridControl();
                }
            }
        }
Esempio n. 6
0
        protected override void OnSaveToolBarItem()
        {
            ReadData(_activePart);
            if (_activePart.Id > 0)
            {
                var activeUserId = ApplicationSessionService.GetActiveUserId();
                var creationDate = ApplicationSessionService.GetNowDateTime();

                using (var dbContext = new FarnahadManufacturingDbContext())
                {
                    var partInDb = dbContext.Parts
                                   .Include(item => item.PartReorderInformations)
                                   .First(item => item.Id == _activePart.Id);
                    var newCost = _activePart.PartCosts.FirstOrDefault(item => item.CreatedByUserId == 0);
                    if (newCost != null)
                    {
                        newCost.CreatedByUserId = activeUserId;
                        newCost.CreatedDateTime = creationDate;
                        newCost.PartId          = partInDb.Id;
                        partInDb.PartCosts.Add(newCost);
                    }

                    foreach (var defaultLocation in _activePart.PartDefaultLocations)
                    {
                        if (defaultLocation.PartId == 0)
                        {
                            defaultLocation.PartId = _activePart.Id;
                            partInDb.PartDefaultLocations.Add(defaultLocation);
                        }
                        else
                        {
                            var defaultLocationInDb = dbContext.PartDefaultLocations
                                                      .First(item => item.Id == defaultLocation.Id);
                            defaultLocationInDb.LocationGroupId   = defaultLocation.LocationGroupId;
                            defaultLocationInDb.DefaultLocationId = defaultLocation.DefaultLocationId;
                            defaultLocationInDb.Part = partInDb;
                        }
                    }

                    foreach (var trackingPart in _activePart.TrackingParts)
                    {
                        if (trackingPart.PartId == 0)
                        {
                            trackingPart.PartId          = _activePart.Id;
                            trackingPart.CreatedByUserId = activeUserId;
                            trackingPart.CreatedDateTime = creationDate;
                            partInDb.TrackingParts.Add(trackingPart);
                        }
                        else
                        {
                            var trackingPartInDb = dbContext.TrackingParts
                                                   .First(item => item.Id == trackingPart.Id);
                            trackingPartInDb.Description = trackingPart.Description;
                            trackingPartInDb.IsPrimary   = trackingPart.IsPrimary;
                            trackingPartInDb.IsSelected  = trackingPart.IsSelected;
                            trackingPartInDb.NextValue   = trackingPart.NextValue;
                            trackingPartInDb.TrackingId  = trackingPart.TrackingId;
                            trackingPartInDb.Part        = partInDb;
                        }
                    }

                    foreach (var partReorderInformation in _activePart.PartReorderInformations)
                    {
                        if (partReorderInformation.PartId == 0)
                        {
                            partReorderInformation.PartId          = _activePart.Id;
                            partReorderInformation.CreatedByUserId = activeUserId;
                            partReorderInformation.CreatedDateTime = creationDate;
                            partInDb.PartReorderInformations.Add(partReorderInformation);
                        }
                        else
                        {
                            var partReorderInformationInDb = dbContext.PartReorderInformations
                                                             .First(item => item.Id == partReorderInformation.Id);
                            partReorderInformationInDb.LocationGroupId = partReorderInformation.LocationGroupId;
                            partReorderInformationInDb.OrderUpToLevel  = partReorderInformation.OrderUpToLevel;
                            partReorderInformationInDb.ReorderPoint    = partReorderInformation.ReorderPoint;
                            partReorderInformationInDb.Part            = partInDb;
                        }
                    }

                    foreach (var partReorderInformation in partInDb.PartReorderInformations.ToList())
                    {
                        if (_activePart.PartReorderInformations.All(item => item.Id != partReorderInformation.Id))
                        {
                            dbContext.Entry(partReorderInformation).State = EntityState.Deleted;
                        }
                    }

                    //_activePart.Products;

                    partInDb.Title             = _activePart.Title;
                    partInDb.Number            = _activePart.Number;
                    partInDb.UomId             = _activePart.UomId;
                    partInDb.PartType          = _activePart.PartType;
                    partInDb.Description       = _activePart.Description;
                    partInDb.Details           = _activePart.Details;
                    partInDb.IsActive          = _activePart.IsActive;
                    partInDb.PickInPartUomOnly = _activePart.PickInPartUomOnly;
                    partInDb.Picture           = _activePart.Picture;

                    partInDb.RevisionNumber = _activePart.RevisionNumber;
                    partInDb.Upc            = _activePart.Upc;
                    partInDb.AlertNote      = _activePart.AlertNote;
                    partInDb.Length         = _activePart.Length;
                    partInDb.Width          = _activePart.Width;
                    partInDb.Height         = _activePart.Height;
                    partInDb.DistanceUomId  = _activePart.DistanceUomId;
                    partInDb.Weight         = _activePart.Weight;
                    partInDb.WeightUomId    = _activePart.WeightUomId;

                    partInDb.PartAbcCode = _activePart.PartAbcCode;

                    partInDb.LastChangedByUserId = activeUserId;
                    partInDb.LastChangedDateTime = creationDate;

                    dbContext.SaveChanges();

                    IsEditing();
                }
            }
            else
            {
                using (var dbContext = new FarnahadManufacturingDbContext())
                {
                    var activeUserId = ApplicationSessionService.GetActiveUserId();
                    var creationDate = ApplicationSessionService.GetNowDateTime();
                    _activePart.CreatedByUserId     = activeUserId;
                    _activePart.LastChangedByUserId = activeUserId;
                    _activePart.CreatedDateTime     = creationDate;
                    _activePart.LastChangedDateTime = creationDate;
                    foreach (var trackingPart in _activePart.TrackingParts)
                    {
                        dbContext.Trackings.Attach(trackingPart.Tracking);
                        trackingPart.CreatedByUserId = activeUserId;
                        trackingPart.CreatedDateTime = creationDate;
                    }

                    foreach (var partCost in _activePart.PartCosts)
                    {
                        partCost.CreatedByUserId = activeUserId;
                        partCost.CreatedDateTime = creationDate;
                    }

                    foreach (var reorderInformation in _activePart.PartReorderInformations)
                    {
                        reorderInformation.CreatedByUserId = activeUserId;
                        reorderInformation.CreatedDateTime = creationDate;
                    }

                    dbContext.Parts.Add(_activePart);
                    dbContext.SaveChanges();

                    OnAddToolBarItem();
                }
            }

            MessageBoxService.SaveConfirmation(_activePart.Title);
            LoadSearchGridControl();
        }
        protected override void OnSaveToolBarItem()
        {
            ReadData(_activeProduct);
            if (_activeProduct.Id > 0)
            {
                var activeUserId = ApplicationSessionService.GetActiveUserId();
                var creationDate = ApplicationSessionService.GetNowDateTime();

                using (var dbContext = new FarnahadManufacturingDbContext())
                {
                    var productInDb = dbContext.Products
                                      .Include(item => item.ProductPrices)
                                      .Include(item => item.ProductSubstitutes)
                                      .Include(item => item.ProductAssociatePrices)
                                      .First(item => item.Id == _activeProduct.Id);
                    var newPrice = _activeProduct.ProductPrices.FirstOrDefault(item => item.CreatedByUserId == 0);
                    if (newPrice != null)
                    {
                        newPrice.CreatedByUserId = activeUserId;
                        newPrice.CreatedDateTime = creationDate;
                        newPrice.ProductId       = productInDb.Id;
                        productInDb.ProductPrices.Add(newPrice);
                    }

                    foreach (var productAssociatePrice in _activeProduct.ProductAssociatePrices)
                    {
                        if (productAssociatePrice.ProductId == 0)
                        {
                            productAssociatePrice.ProductId       = _activeProduct.Id;
                            productAssociatePrice.CreatedByUserId = activeUserId;
                            productAssociatePrice.CreatedDateTime = creationDate;
                            productInDb.ProductAssociatePrices.Add(productAssociatePrice);
                        }
                        else
                        {
                            var productAssociatePriceInDb = dbContext.ProductAssociatePrices
                                                            .First(item => item.Id == productAssociatePrice.Id);
                            productAssociatePriceInDb.ProductAssociatedPriceTypeId = productAssociatePrice.ProductAssociatedPriceTypeId;
                            productAssociatePriceInDb.Price   = productAssociatePrice.Price;
                            productAssociatePriceInDb.Product = productInDb;
                        }
                    }

                    foreach (var productAssociatePrice in productInDb.ProductAssociatePrices.ToList())
                    {
                        if (_activeProduct.ProductAssociatePrices.All(item => item.Id != productAssociatePrice.Id))
                        {
                            dbContext.Entry(productAssociatePrice).State = EntityState.Deleted;
                        }
                    }

                    foreach (var productSubstitute in _activeProduct.ProductSubstitutes)
                    {
                        if (productSubstitute.ProductId == 0)
                        {
                            productSubstitute.ProductId       = _activeProduct.Id;
                            productSubstitute.CreatedByUserId = activeUserId;
                            productSubstitute.CreatedDateTime = creationDate;
                            productInDb.ProductSubstitutes.Add(productSubstitute);
                        }
                        else
                        {
                            var productSubstituteInDb = dbContext.ProductSubstitutes.First(item => item.Id == productSubstitute.Id);
                            productSubstituteInDb.SubstituteProductId = productSubstitute.SubstituteProductId;
                            productSubstituteInDb.Note    = productSubstitute.Note;
                            productSubstituteInDb.Product = productInDb;
                        }
                    }

                    foreach (var productSubstitute in productInDb.ProductSubstitutes.ToList())
                    {
                        if (_activeProduct.ProductSubstitutes.All(item => item.Id != productSubstitute.Id))
                        {
                            dbContext.Entry(productSubstitute).State = EntityState.Deleted;
                        }
                    }

                    productInDb.Title                 = _activeProduct.Title;
                    productInDb.PartId                = _activeProduct.PartId;
                    productInDb.UomId                 = _activeProduct.UomId;
                    productInDb.Description           = _activeProduct.Description;
                    productInDb.Detail                = _activeProduct.Detail;
                    productInDb.IsActive              = _activeProduct.IsActive;
                    productInDb.AllowToSellInOtherUom = _activeProduct.AllowToSellInOtherUom;
                    productInDb.CategoryId            = _activeProduct.CategoryId;
                    productInDb.IsTaxable             = _activeProduct.IsTaxable;
                    productInDb.ShowOnSaleOrder       = _activeProduct.ShowOnSaleOrder;
                    productInDb.Picture               = _activeProduct.Picture;

                    productInDb.Sku               = _activeProduct.Sku;
                    productInDb.Upc               = _activeProduct.Upc;
                    productInDb.AlertNote         = _activeProduct.AlertNote;
                    productInDb.SaleOrderItemType = _activeProduct.SaleOrderItemType;
                    productInDb.Length            = _activeProduct.Length;
                    productInDb.Width             = _activeProduct.Width;
                    productInDb.Height            = _activeProduct.Height;
                    productInDb.DistanceUomId     = _activeProduct.DistanceUomId;
                    productInDb.Weight            = _activeProduct.Weight;
                    productInDb.WeightUomId       = _activeProduct.WeightUomId;

                    dbContext.SaveChanges();

                    IsEditing();
                }
            }
            else
            {
                var activeUserId = ApplicationSessionService.GetActiveUserId();
                var createDate   = ApplicationSessionService.GetNowDateTime();
                _activeProduct.CreatedByUserId = activeUserId;
                _activeProduct.CreatedDateTime = createDate;

                using (var dbContext = new FarnahadManufacturingDbContext())
                {
                    foreach (var productAssociatePrice in _activeProduct.ProductAssociatePrices)
                    {
                        productAssociatePrice.CreatedByUserId = activeUserId;
                        productAssociatePrice.CreatedDateTime = createDate;
                    }
                    foreach (var productPrice in _activeProduct.ProductPrices)
                    {
                        productPrice.CreatedByUserId = activeUserId;
                        productPrice.CreatedDateTime = createDate;
                    }
                    foreach (var productSubstitute in _activeProduct.ProductSubstitutes)
                    {
                        productSubstitute.CreatedByUserId = activeUserId;
                        productSubstitute.CreatedDateTime = createDate;
                    }

                    dbContext.Products.Add(_activeProduct);
                    dbContext.SaveChanges();

                    OnAddToolBarItem();
                }
            }

            MessageBoxService.SaveConfirmation(_activeProduct.Title);
            LoadSearchGridControl();
        }
        private void SaveButtonOnItemClick(object sender, ItemClickEventArgs e)
        {
            ReadData(_myCompany);
            ReadData(_activeAddress);
            using (var dbContext = new FarnahadManufacturingDbContext())
            {
                var myCompanyInDb = dbContext.MyCompanies.Find(_myCompany.Id);

                myCompanyInDb.Title                   = _myCompany.Title;
                myCompanyInDb.IsTaxExempt             = _myCompany.IsTaxExempt;
                myCompanyInDb.DefaultCarrierId        = _myCompany.DefaultCarrierId;
                myCompanyInDb.DefaultCarrierServiceId = _myCompany.DefaultCarrierServiceId;
                myCompanyInDb.Logo = _myCompany.Logo;

                var addressesInDbs = dbContext.Addresses.Where(item => item.CompanyId == _myCompany.Id).ToList();
                foreach (var addressInDb in addressesInDbs)
                {
                    var address = _myCompany.Addresses.FirstOrDefault(item => item.Id == addressInDb.Id);
                    if (address != null)
                    {
                        addressInDb.Title                = address.Title;
                        addressInDb.AddressDetail        = address.AddressDetail;
                        addressInDb.IsDefaultAddress     = address.IsDefaultAddress;
                        addressInDb.ProvinceId           = address.ProvinceId;
                        addressInDb.AddressTypeId        = address.AddressTypeId;
                        addressInDb.CityId               = address.CityId;
                        addressInDb.CountryId            = address.CountryId;
                        addressInDb.IsResidentialAddress = address.IsResidentialAddress;
                        addressInDb.Latitude             = address.Latitude;
                        addressInDb.Longitude            = address.Longitude;
                        addressInDb.ZipCode              = address.ZipCode;

                        var contactInformationsInDbs = dbContext.ContactInformations.Where(item => item.AddressId == addressInDb.Id).ToList();
                        foreach (var contactInformationInDb in contactInformationsInDbs)
                        {
                            var contactInformation = address.ContactInformations.FirstOrDefault(item => item.Id == contactInformationInDb.Id);
                            if (contactInformation != null)
                            {
                                contactInformationInDb.Title       = contactInformation.Title;
                                contactInformationInDb.IsDefault   = contactInformation.IsDefault;
                                contactInformationInDb.ContactType = contactInformation.ContactType;
                                contactInformationInDb.Value       = contactInformation.Value;
                            }
                            else
                            {
                                dbContext.ContactInformations.Remove(contactInformationInDb);
                            }
                        }
                        foreach (var contactInformation in address.ContactInformations.Where(item => item.Id <= 0))
                        {
                            contactInformation.CreatedByUserId = ApplicationSessionService.GetActiveUserId();
                            contactInformation.CreatedDateTime = ApplicationSessionService.GetNowDateTime();
                            addressInDb.ContactInformations.Add(contactInformation);
                        }
                    }
                    else
                    {
                        dbContext.ContactInformations.RemoveRange(addressInDb.ContactInformations);
                        dbContext.Addresses.Remove(addressInDb);
                    }
                }

                foreach (var address in _myCompany.Addresses.Where(item => item.Id <= 0))
                {
                    address.CreatedByUserId = ApplicationSessionService.GetActiveUserId();
                    address.CreatedDateTime = ApplicationSessionService.GetNowDateTime();
                    foreach (var contactInformation in address.ContactInformations)
                    {
                        contactInformation.CreatedByUserId = ApplicationSessionService.GetActiveUserId();
                        contactInformation.CreatedDateTime = ApplicationSessionService.GetNowDateTime();
                    }
                    myCompanyInDb.Addresses.Add(address);
                }
                dbContext.SaveChanges();
            }

            MessageBoxService.SaveConfirmation(_myCompany.Title);
            LoadMyCompany();
        }
        protected override void OnSaveToolBarItem()
        {
            ReadData(_activeVendor);
            ReadData(_activeAddress);
            using (var dbContext = new FarnahadManufacturingDbContext())
            {
                if (_activeVendor.Id > 0)
                {
                    var vendorInDb = dbContext.Vendors.Find(_activeVendor.Id);

                    vendorInDb.Title = _activeVendor.Title;
                    vendorInDb.DefaultPaymentTermId    = _activeVendor.DefaultPaymentTermId;
                    vendorInDb.AccountNumber           = _activeVendor.AccountNumber;
                    vendorInDb.MinOrderAmount          = _activeVendor.MinOrderAmount;
                    vendorInDb.DefaultCarrierId        = _activeVendor.DefaultCarrierId;
                    vendorInDb.DefaultCarrierServiceId = _activeVendor.DefaultCarrierServiceId;
                    vendorInDb.DefaultShippingTermId   = _activeVendor.DefaultPaymentTermId;
                    vendorInDb.Logo = _activeVendor.Logo;

                    var addressesInDbs = dbContext.Addresses.Where(item => item.CompanyId == _activeVendor.Id).ToList();
                    foreach (var addressInDb in addressesInDbs)
                    {
                        var address = _activeVendor.Addresses.FirstOrDefault(item => item.Id == addressInDb.Id);
                        if (address != null)
                        {
                            addressInDb.Title                = address.Title;
                            addressInDb.AddressDetail        = address.AddressDetail;
                            addressInDb.IsDefaultAddress     = address.IsDefaultAddress;
                            addressInDb.ProvinceId           = address.ProvinceId;
                            addressInDb.AddressTypeId        = address.AddressTypeId;
                            addressInDb.CityId               = address.CityId;
                            addressInDb.CountryId            = address.CountryId;
                            addressInDb.IsResidentialAddress = address.IsResidentialAddress;
                            addressInDb.Latitude             = address.Latitude;
                            addressInDb.Longitude            = address.Longitude;
                            addressInDb.ZipCode              = address.ZipCode;

                            var contactInformationsInDbs = dbContext.ContactInformations.Where(item => item.AddressId == addressInDb.Id).ToList();
                            foreach (var contactInformationInDb in contactInformationsInDbs)
                            {
                                var contactInformation = address.ContactInformations.FirstOrDefault(item => item.Id == contactInformationInDb.Id);
                                if (contactInformation != null)
                                {
                                    contactInformationInDb.Title       = contactInformation.Title;
                                    contactInformationInDb.IsDefault   = contactInformation.IsDefault;
                                    contactInformationInDb.ContactType = contactInformation.ContactType;
                                    contactInformationInDb.Value       = contactInformation.Value;
                                }
                                else
                                {
                                    dbContext.ContactInformations.Remove(contactInformationInDb);
                                }
                            }
                            foreach (var contactInformation in address.ContactInformations.Where(item => item.Id <= 0))
                            {
                                contactInformation.CreatedByUserId = ApplicationSessionService.GetActiveUserId();
                                contactInformation.CreatedDateTime = ApplicationSessionService.GetNowDateTime();
                                addressInDb.ContactInformations.Add(contactInformation);
                            }
                        }
                        else
                        {
                            dbContext.ContactInformations.RemoveRange(addressInDb.ContactInformations);
                            dbContext.Addresses.Remove(addressInDb);
                        }
                    }

                    foreach (var address in _activeVendor.Addresses.Where(item => item.Id <= 0))
                    {
                        address.CreatedByUserId = ApplicationSessionService.GetActiveUserId();
                        address.CreatedDateTime = ApplicationSessionService.GetNowDateTime();
                        foreach (var contactInformation in address.ContactInformations)
                        {
                            contactInformation.CreatedByUserId = ApplicationSessionService.GetActiveUserId();
                            contactInformation.CreatedDateTime = ApplicationSessionService.GetNowDateTime();
                        }
                        vendorInDb.Addresses.Add(address);
                    }
                    dbContext.SaveChanges();

                    IsEditing();
                }
                else
                {
                    _activeVendor.Addresses = _addresses.ToList();
                    foreach (var address in _activeVendor.Addresses)
                    {
                        address.CreatedByUserId = ApplicationSessionService.GetActiveUserId();
                        address.CreatedDateTime = ApplicationSessionService.GetNowDateTime();
                        foreach (var contactInformation in address.ContactInformations)
                        {
                            contactInformation.CreatedByUserId = ApplicationSessionService.GetActiveUserId();
                            contactInformation.CreatedDateTime = ApplicationSessionService.GetNowDateTime();
                        }
                    }
                    _activeVendor.CreatedByUserId = ApplicationSessionService.GetActiveUserId();
                    _activeVendor.CreatedDateTime = ApplicationSessionService.GetNowDateTime();
                    dbContext.Vendors.Add(_activeVendor);

                    dbContext.SaveChanges();

                    OnAddToolBarItem();
                }
            }

            MessageBoxService.SaveConfirmation(_activeVendor.Title);
            LoadSearchGridControl();
        }