Esempio n. 1
0
        //public async Task<int> AddVendorAsync(Vendor vendor)
        //{
        //    try
        //    {
        //        if (vendor == null)
        //            return 0;

        //        var entity = new Vendor()
        //        {
        //            VendorName = vendor.VendorName,
        //            VendorGuid = vendor.VendorGuid,
        //            VendorAlias = vendor.VendorAlias,
        //            VendorSalutation = vendor.VendorSalutation,
        //            AadharNo = vendor.AadharNo,
        //            ContactPerson = vendor.ContactPerson,
        //            PAN = vendor.PAN,
        //            GSTIN = vendor.GSTIN,
        //            email = vendor.email,
        //            IsVendorActive = vendor.IsVendorActive,
        //            PhoneNo = vendor.PhoneNo,
        //            AddressLine1 = vendor.AddressLine1,
        //            AddressLine2 = vendor.AddressLine2,
        //            City = vendor.City,
        //            PinCode = vendor.PinCode
        //        };
        //        _dataSource.Entry(entity).State = EntityState.Added;
        //        int res = await _dataSource.SaveChangesAsync();
        //        return res;
        //    }
        //    catch (Exception ex)
        //    {
        //        return 0;
        //    }
        //}

        public async Task <int> UpdateVendorAsync(Vendor vendor)
        {
            try
            {
                ICollection <VendorDocuments> docs = vendor.VendorDocuments;
                vendor.VendorDocuments = null;
                if (vendor.VendorId > 0)
                {
                    _dataSource.Entry(vendor).State = EntityState.Modified;
                }
                else
                {
                    vendor.VendorGuid = Guid.NewGuid();
                    //Company.CreatedOn = DateTime.UtcNow;
                    _dataSource.Entry(vendor).State = EntityState.Added;
                }
                vendor.SearchTerms = vendor.BuildSearchTerms();
                int res = await _dataSource.SaveChangesAsync();

                if (docs != null)
                {
                    foreach (var doc in docs)
                    {
                        if (doc.VendorBlobId == 0)
                        {
                            doc.VendorGuid = vendor.VendorGuid;
                            _dataSource.VendorDocuments.Add(doc);
                        }
                    }
                }
                await _dataSource.SaveChangesAsync();

                return(res);
            }
            catch (Exception ex) {
                throw ex;
            }
        }