예제 #1
0
 public static bool AddContractor(ContractorModel Obj)
 {
     using (var dbContext = new BSSDBEntities())
     {
         var Check = dbContext.tblContractorMasters.Where(x => x.ContractorCode == Obj.ContractorCode && x.DealerID == Obj.DealerID && x.AccountID == Obj.AccountID).FirstOrDefault();
         if (Check == null)
         {
             tblContractorMaster Cm = new tblContractorMaster()
             {
                 ContractorName = Obj.ContractorName,
                 ContractorCode = Obj.ContractorCode,
                 CreatedBy      = Obj.CreatedBy,
                 AccountID      = Obj.AccountID,
                 IsDeleted      = false,
                 Address        = Obj.Address,
                 Phone          = Obj.Phone,
                 CreationDate   = DateTime.Now,
                 DealerID       = Obj.DealerID
             };
             dbContext.Entry(Cm).State = System.Data.Entity.EntityState.Added;
             dbContext.SaveChanges();
             return(true);
         }
         else
         {
             return(false);
         }
     }
 }
예제 #2
0
        public static void InsertIntoTblContractor(DataTable info, SessionDataBLL obj)
        {
            using (var context = new BSSDBEntities())
            {
                foreach (DataRow Dr in info.Rows)
                {
                    string ContractorName = Dr["ContractorName"].ToString().Trim();
                    string ContractorCode = Convert.ToString(Dr["ContractorCode"]);
                    if (ContractorCode != null && ContractorCode != string.Empty && ContractorName != null && ContractorName != string.Empty)
                    {
                        string ContractorAddress = Convert.ToString(Dr["ContractorAddress"]);
                        string PhoneNo           = Convert.ToString(Dr["PhoneNo"]);

                        var Check = context.tblContractorMasters.Where(x => x.ContractorCode == ContractorCode && x.DealerID == obj.DealerID).FirstOrDefault();

                        if (Check == null)
                        {
                            tblContractorMaster dt = new tblContractorMaster
                            {
                                ContractorCode = ContractorCode,
                                ContractorName = ContractorName,
                                IsDeleted      = false,
                                Address        = ContractorAddress,
                                AccountID      = obj.AccountId,
                                DealerID       = obj.DealerID,
                                Phone          = PhoneNo,
                                CreatedBy      = Convert.ToString(obj.UserId),
                                CreationDate   = DateTime.Now
                            };
                            context.Entry(dt).State = EntityState.Added;
                            context.SaveChanges();
                        }
                        else
                        {
                            continue;
                        }
                    }
                }
            }
        }