Inheritance: DbContext
Exemple #1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="FieldChange"/> class.
        /// </summary>
        /// <param name="a">A.</param>
        /// <param name="property">The property.</param>
        /// <param name="foreignTable">The foreign table.</param>
        /// <param name="foreignFeildName">Name of the foreign feild.</param>
        /// <param name="foreignFeildKey">The foreign feild key.</param>
        public FieldChange(Audit a, string property, string foreignTable, string foreignFeildName, string foreignFeildKey)
        {
            //FieldChange x = new FieldChange(a, property);
            CTSContext db = new CTSContext();

            //   this.ChangeDate = a.DateTime;
            BLL.UserProfile user = BLL.UserProfile.GetUserById(a.LoginID);
            this.ChangedBy = (user != null) ? user.UserName : "******";
            this.FieldName = property;

            this.PreviousValue = a.OldValue;
            this.ChangedValue  = a.NewValue;

            this.FieldName = property;

            var prevKey    = Convert.ToInt32(this.PreviousValue);
            var CurrentKey = Convert.ToInt32(this.ChangedValue);
            //modified Banty:24/5/2013 from db.ExecuteStoreQuery to (db as IObjectContextAdapter).ObjectContext.ExecuteStoreQuery
            var Prev = (db as IObjectContextAdapter).ObjectContext.ExecuteStoreQuery <string>(" SELECT " + foreignFeildName + " as field FROM " + foreignTable + " WHERE " + foreignFeildKey + " = " + prevKey).FirstOrDefault();
            var now  = (db as IObjectContextAdapter).ObjectContext.ExecuteStoreQuery <string>(" SELECT " + foreignFeildName + " as field FROM " + foreignTable + " WHERE " + foreignFeildKey + " = " + CurrentKey).FirstOrDefault();;

            // var Prev = db.AuditForeignFeild(foreignTable,foreignFeildName,prevKey,foreignFeildKey).SingleOrDefault();
            // var now = db.AuditForeignFeild(foreignTable, foreignFeildName, CurrentKey, foreignFeildKey).SingleOrDefault();

            if (Prev != null)
            {
                this.PreviousValue = Prev.ToString();
                //this.PreviousValue = Prev.field;
            }
            if (now != null)
            {
                this.ChangedValue = now.ToString();
            }
        }
Exemple #2
0
        public static bool RoleExists(string name)
        {
            CTSContext entities = new CTSContext();
            var        count    = entities.Roles.Where(p => p.Name == name).Count();

            return(count > 0);
        }
Exemple #3
0
        /// <summary>
        /// Initializes a new instance of the <see cref="FieldChange"/> class.
        /// </summary>
        /// <param name="a">A.</param>
        /// <param name="property">The property.</param>
        /// <param name="foreignTable">The foreign table.</param>
        /// <param name="foreignFeildName">Name of the foreign feild.</param>
        /// <param name="foreignFeildKey">The foreign feild key.</param>
        public FieldChange(Audit a, string property, string foreignTable, string foreignFeildName, string foreignFeildKey)
        {
            //FieldChange x = new FieldChange(a, property);
            CTSContext db = new CTSContext();

             //   this.ChangeDate = a.DateTime;
            BLL.UserProfile user = BLL.UserProfile.GetUserById(a.LoginID);
            this.ChangedBy = (user != null) ? user.UserName : "******";
            this.FieldName = property;

            this.PreviousValue = a.OldValue;
            this.ChangedValue = a.NewValue;

            this.FieldName = property;

            var prevKey = Convert.ToInt32(this.PreviousValue);
            var CurrentKey = Convert.ToInt32(this.ChangedValue);
            //modified Banty:24/5/2013 from db.ExecuteStoreQuery to (db as IObjectContextAdapter).ObjectContext.ExecuteStoreQuery
            var Prev = (db as IObjectContextAdapter).ObjectContext.ExecuteStoreQuery<string>(" SELECT " + foreignFeildName + " as field FROM " + foreignTable + " WHERE " + foreignFeildKey + " = " + prevKey).FirstOrDefault();
            var now = (db as IObjectContextAdapter).ObjectContext.ExecuteStoreQuery<string>(" SELECT " + foreignFeildName + " as field FROM " + foreignTable + " WHERE " + foreignFeildKey + " = " + CurrentKey).FirstOrDefault(); ;
             // var Prev = db.AuditForeignFeild(foreignTable,foreignFeildName,prevKey,foreignFeildKey).SingleOrDefault();
             // var now = db.AuditForeignFeild(foreignTable, foreignFeildName, CurrentKey, foreignFeildKey).SingleOrDefault();

            if(Prev != null)
            {
                this.PreviousValue = Prev.ToString();
                //this.PreviousValue = Prev.field;
            }
            if(now != null)
            {
                this.ChangedValue = now.ToString();
            }
        }
Exemple #4
0
        public static void AddRole(Role role)
        {
            CTSContext entities = new CTSContext();

            entities.Roles.Add(role);
            entities.SaveChanges();
        }
Exemple #5
0
        public static Role GetRole(string name)
        {
            CTSContext entities = new CTSContext();

            return(entities.Roles.Where(p => p.Name == name).SingleOrDefault());

            ;
        }
Exemple #6
0
        /// <summary>
        /// Determines whether the specified id has updated.
        /// </summary>
        /// <param name="id">The id.</param>
        /// <param name="table">The table.</param>
        /// <returns>
        ///   <c>true</c> if the specified id has updated; otherwise, <c>false</c>.
        /// </returns>
        public static bool HasUpdated(int id, string table)
        {
            CTSContext db    = new CTSContext();
            var        count = (from audit in db.Audits
                                where audit.TableName == table && audit.PrimaryKey == id.ToString()
                                select audit).Count();

            return(count > 0);
        }
Exemple #7
0
 public void RemoveRole(string roleName, string userName)
 {
     BLL.CTSContext entities = new CTSContext();
     UserRole role = entities.UserRoles.Where(r => r.Role.Name == roleName && r.UserProfile.UserName == userName).SingleOrDefault();
     if (role != null)
     {
         entities.UserRoles.Remove(role);
         entities.SaveChanges();
     }
 }
Exemple #8
0
        public void RemoveRole(string roleName, string userName)
        {
            BLL.CTSContext entities = new CTSContext();
            UserRole       role     = entities.UserRoles.Where(r => r.Role.Name == roleName && r.UserProfile.UserName == userName).SingleOrDefault();

            if (role != null)
            {
                entities.UserRoles.Remove(role);
                entities.SaveChanges();
            }
        }
Exemple #9
0
 /// <summary>
 /// Determines whether the specified id has updated.
 /// </summary>
 /// <param name="id">The id.</param>
 /// <param name="table">The table.</param>
 /// <param name="property">The property.</param>
 /// <returns>
 ///   <c>true</c> if the specified id has updated; otherwise, <c>false</c>.
 /// </returns>
 public static bool HasUpdated(object id, string table, string property)
 {
     if (id != null)
     {
         string     stringId = id.ToString();
         CTSContext db       = new CTSContext();
         var        count    = (from audit in db.Audits
                                where audit.TableName == table && audit.PrimaryKey.Equals(stringId) && audit.NewValue.Contains(property)
                                select audit).Count();
         return(count > 0);
     }
     return(false);
 }
Exemple #10
0
 public void AddUserToRole(int roleId, string userName)
 {
     BLL.CTSContext entities = new CTSContext();
     UserProfile user = entities.UserProfiles.Where(p => p.UserName == userName).FirstOrDefault();
     if (user != null)
     {
         UserRole role = new UserRole();
         role.RoleID = roleId;
         role.UserProfileID = user.UserProfileID;
         entities.UserRoles.Add(role);
         entities.SaveChanges();
     }
 }
Exemple #11
0
        public void AddUserToRole(int roleId, string userName)
        {
            BLL.CTSContext entities = new CTSContext();
            UserProfile    user     = entities.UserProfiles.Where(p => p.UserName == userName).FirstOrDefault();

            if (user != null)
            {
                UserRole role = new UserRole();
                role.RoleID        = roleId;
                role.UserProfileID = user.UserProfileID;
                entities.UserRoles.Add(role);
                entities.SaveChanges();
            }
        }
Exemple #12
0
        /// <summary>
        /// Updates the specified inserted.
        /// </summary>
        /// <param name="inserted">The inserted.</param>
        /// <param name="updated">The updated.</param>
        /// <param name="deleted">The deleted.</param>
        public void Update(List <BLL.DispatchDetail> inserted, List <BLL.DispatchDetail> updated,
                           List <BLL.DispatchDetail> deleted)
        {
            CTSContext db = new CTSContext();

            BLL.Dispatch orginal = db.Dispatches.Where(p => p.DispatchID == this.DispatchID).SingleOrDefault();
            if (orginal != null)
            {
                orginal.BidNumber       = this.BidNumber;
                orginal.DispatchDate    = this.DispatchDate;
                orginal.DriverName      = this.DriverName;
                orginal.FDPID           = this.FDPID;
                orginal.GIN             = this.GIN;
                orginal.PeriodYear      = this.PeriodYear;
                orginal.PeriodMonth     = this.PeriodMonth;
                orginal.PlateNo_Prime   = this.PlateNo_Prime;
                orginal.PlateNo_Trailer = this.PlateNo_Trailer;
                //orginal.ProgramID = this.ProgramID;
                orginal.RequisitionNo = this.RequisitionNo;
                orginal.Round         = this.Round;
                //orginal.StackNumber = this.StackNumber;
                //orginal.StoreID = this.StoreID;
                orginal.TransporterID = this.TransporterID;
                orginal.UserProfileID = this.UserProfileID;
                //orginal.WarehouseID = this.WarehouseID;
                orginal.WeighBridgeTicketNumber = this.WeighBridgeTicketNumber;
                orginal.Remark = this.Remark;
                orginal.DispatchedByStoreMan = this.DispatchedByStoreMan;
                //orginal.ProjectNumber = this.ProjectNumber;
                //orginal.SINumber = this.SINumber;



                foreach (BLL.DispatchDetail update in updated)
                {
                    BLL.DispatchDetail updatedCommodity = db.DispatchDetails.Where(p => p.DispatchDetailID == update.DispatchDetailID).SingleOrDefault();
                    if (updatedCommodity != null)
                    {
                        updatedCommodity.CommodityID = update.CommodityID;
                        updatedCommodity.Description = update.Description;
                        //updatedCommodity.DispatchedQuantityInUnit = update.DispatchedQuantityInUnit;
                        //updatedCommodity.DispatchedQuantityInMT = update.DispatchedQuantityInMT;
                        updatedCommodity.RequestedQunatityInUnit = update.RequestedQunatityInUnit;
                        updatedCommodity.RequestedQuantityInMT   = update.RequestedQuantityInMT;
                        updatedCommodity.UnitID = update.UnitID;
                    }
                }
                db.SaveChanges();
            }
        }
Exemple #13
0
        /// <summary>
        /// Updates the specified inserted.
        /// </summary>
        /// <param name="inserted">The inserted.</param>
        /// <param name="updated">The updated.</param>
        /// <param name="deleted">The deleted.</param>
        public void Update(List<BLL.DispatchDetail> inserted, List<BLL.DispatchDetail> updated, 
            List<BLL.DispatchDetail> deleted)
        {
            CTSContext db = new CTSContext();
            BLL.Dispatch orginal = db.Dispatches.Where(p => p.DispatchID == this.DispatchID).SingleOrDefault();
                    if (orginal != null)
                    {
                        orginal.BidNumber = this.BidNumber;
                        orginal.DispatchDate = this.DispatchDate;
                        orginal.DriverName = this.DriverName;
                        orginal.FDPID = this.FDPID;
                        orginal.GIN = this.GIN;
                        orginal.PeriodYear = this.PeriodYear;
                        orginal.PeriodMonth = this.PeriodMonth;
                        orginal.PlateNo_Prime = this.PlateNo_Prime;
                        orginal.PlateNo_Trailer = this.PlateNo_Trailer;
                        //orginal.ProgramID = this.ProgramID;
                        orginal.RequisitionNo = this.RequisitionNo;
                        orginal.Round = this.Round;
                        //orginal.StackNumber = this.StackNumber;
                        //orginal.StoreID = this.StoreID;
                        orginal.TransporterID = this.TransporterID;
                        orginal.UserProfileID = this.UserProfileID;
                        //orginal.WarehouseID = this.WarehouseID;
                        orginal.WeighBridgeTicketNumber = this.WeighBridgeTicketNumber;
                        orginal.Remark = this.Remark;
                        orginal.DispatchedByStoreMan = this.DispatchedByStoreMan;
                        //orginal.ProjectNumber = this.ProjectNumber;
                        //orginal.SINumber = this.SINumber;

                        foreach (BLL.DispatchDetail update in updated)
                        {
                            BLL.DispatchDetail updatedCommodity = db.DispatchDetails.Where(p => p.DispatchDetailID == update.DispatchDetailID).SingleOrDefault();
                            if (updatedCommodity != null)
                            {
                                updatedCommodity.CommodityID = update.CommodityID;
                                updatedCommodity.Description = update.Description;
                                //updatedCommodity.DispatchedQuantityInUnit = update.DispatchedQuantityInUnit;
                                //updatedCommodity.DispatchedQuantityInMT = update.DispatchedQuantityInMT;
                                updatedCommodity.RequestedQunatityInUnit = update.RequestedQunatityInUnit;
                                updatedCommodity.RequestedQuantityInMT = update.RequestedQuantityInMT;
                                updatedCommodity.UnitID = update.UnitID;
                            }
                        }
                        db.SaveChanges();
                    }
        }
Exemple #14
0
        /// <summary>
        /// Gets the changes.
        /// </summary>
        /// <param name="id">The id.</param>
        /// <param name="table">The table.</param>
        /// <param name="property">The property.</param>
        /// <returns></returns>
        public static List <FieldChange> GetChanges(int id, string table, string property)
        {
            string     key     = id.ToString();
            CTSContext db      = new CTSContext();
            var        changes = (from audit in db.Audits
                                  where audit.TableName == table && audit.PrimaryKey == key && audit.NewValue.Contains(property)
                                  orderby audit.DateTime descending
                                  select audit);

            List <FieldChange> filedsList = new List <FieldChange>();

            foreach (Audit a in changes)
            {
                filedsList.Add(new FieldChange(a, property));
            }
            return(filedsList);
        }
Exemple #15
0
        /// <summary>
        /// Gets the SMS text.
        /// </summary>
        /// <returns></returns>
        public string GetSMSText()
        {
            StringBuilder builder = new StringBuilder();
            CTSContext entities = new CTSContext();
            BLL.Dispatch dispatch  = entities.Dispatches.Where(d => d.DispatchID == this.DispatchID).SingleOrDefault();
            if (dispatch != null)
            {
                BLL.DispatchDetail com = dispatch.DispatchDetails.FirstOrDefault();
                if (com != null)
                {
                    builder.Append(string.Format("There is a Dispatch with an ammount of {0}(MT) - {1} to your FDP({2}) ", com.RequestedQuantityInMT, com.Commodity.Name, dispatch.FDP.Name));
                    builder.Append(string.Format("on a car with plate no - {0}", dispatch.PlateNo_Prime));
                }
            }

            return builder.ToString();
        }
Exemple #16
0
        /// <summary>
        /// Gets the SMS text.
        /// </summary>
        /// <returns></returns>
        public string GetSMSText()
        {
            StringBuilder builder  = new StringBuilder();
            CTSContext    entities = new CTSContext();

            BLL.Dispatch dispatch = entities.Dispatches.Where(d => d.DispatchID == this.DispatchID).SingleOrDefault();
            if (dispatch != null)
            {
                BLL.DispatchDetail com = dispatch.DispatchDetails.FirstOrDefault();
                if (com != null)
                {
                    builder.Append(string.Format("There is a Dispatch with an ammount of {0}(MT) - {1} to your FDP({2}) ", com.RequestedQuantityInMT, com.Commodity.Name, dispatch.FDP.Name));
                    builder.Append(string.Format("on a car with plate no - {0}", dispatch.PlateNo_Prime));
                }
            }

            return(builder.ToString());
        }
Exemple #17
0
        public static void SendSMS(int fdpId, string text)
        {
            CTSContext db       = new CTSContext();
            var        contacts = (from contact in db.Contacts
                                   where contact.FDPID == fdpId
                                   select contact).ToList();

            foreach (Contact contact in contacts)
            {
                //              INSERT SMS (InOutInd, MobileNumber, Text, RequestDate, SendAfterDate, Status, StatusDate, Attempts, EventTag)
                //VALUES ('O', @MobileNumber, @SMSMessage, @Today, @SendAfterDate, 'pending', @Today, 0, 'SEND_SMS')
                SMS sms = new DRMFSS.BLL.SMS();
                sms.Attempts        = 0;
                sms.EventTag        = "SEND_SMS";
                sms.InOutInd        = "O";
                sms.LastAttemptDate = null;
                sms.MobileNumber    = contact.PhoneNo;
                sms.Text            = text;
                sms.RequestDate     = DateTime.Today;
                sms.SendAfterDate   = DateTime.Today;
                sms.Status          = "pending";
                sms.StatusDate      = DateTime.Today;

                db.SMS.Add(sms);
                //try
                //{

                //}
                //catch (Exception e)
                //{

                //}
            }

            db.SaveChanges();
        }
Exemple #18
0
        public static void SendSMS(int fdpId, string text)
        {
            CTSContext db = new CTSContext();
            var contacts = (from contact in db.Contacts
                            where contact.FDPID == fdpId
                            select contact).ToList();
            foreach (Contact contact in contacts)
            {
              //              INSERT SMS (InOutInd, MobileNumber, Text, RequestDate, SendAfterDate, Status, StatusDate, Attempts, EventTag)
              //VALUES ('O', @MobileNumber, @SMSMessage, @Today, @SendAfterDate, 'pending', @Today, 0, 'SEND_SMS')
                SMS sms = new DRMFSS.BLL.SMS();
                sms.Attempts = 0;
                sms.EventTag = "SEND_SMS";
                sms.InOutInd = "O";
                sms.LastAttemptDate = null;
                sms.MobileNumber = contact.PhoneNo;
                sms.Text = text;
                sms.RequestDate = DateTime.Today;
                sms.SendAfterDate = DateTime.Today;
                sms.Status = "pending";
                sms.StatusDate = DateTime.Today;

                db.SMS.Add(sms);
                //try
                //{

                //}
                //catch (Exception e)
                //{

                //}

            }

            db.SaveChanges();
        }
Exemple #19
0
        /// <summary>
        /// Gets the changes.
        /// </summary>
        /// <param name="id">The id.</param>
        /// <param name="table">The table.</param>
        /// <param name="property">The property.</param>
        /// <returns></returns>
        public static List<FieldChange> GetChanges(int id, string table, string property)
        {
            string key = id.ToString();
            CTSContext db = new CTSContext();
            var changes = (from audit in db.Audits
                           where audit.TableName == table && audit.PrimaryKey == key && audit.NewValue.Contains(property)
                          orderby audit.DateTime descending
                          select audit);

            List<FieldChange> filedsList = new List<FieldChange>();
            foreach (Audit a in changes)
            {
                filedsList.Add(new FieldChange(a,property));
            }
            return filedsList;
        }
 public override MembershipUser GetUser(string username, bool userIsOnline)
 {
     var entities = new CTSContext();
     UserProfile user = (from u in entities.UserProfiles
                         where u.UserName == username
                         select u).SingleOrDefault();
     return (user != null) ? GetMembershipUser(user) : null;
 }
Exemple #21
0
        /// <summary>
        /// Updates the specified inserted.
        /// </summary>
        /// <param name="inserted">The inserted.</param>
        /// <param name="updated">The updated.</param>
        /// <param name="deleted">The deleted.</param>
        public void Update(List <BLL.ReceiveDetail> inserted, List <BLL.ReceiveDetail> updated,
                           List <BLL.ReceiveDetail> deleted)
        {
            CTSContext db = new CTSContext();

            BLL.Receive orginal = db.Receives.SingleOrDefault(p => p.ReceiveID == this.ReceiveID);
            if (orginal != null)
            {
                // CreatedDate = DateTime.Now,
                orginal.ReceiptDate = this.ReceiptDate;
                // orginal.ReceiveID = this.ReceiveID;
                orginal.DriverName      = this.DriverName;
                orginal.GRN             = this.GRN;
                orginal.PlateNo_Prime   = this.PlateNo_Prime;
                orginal.PlateNo_Trailer = this.PlateNo_Trailer;
                //orginal.StackNumber = this.StackNumber;
                orginal.TransporterID = this.TransporterID;
                orginal.HubID         = this.HubID;
                // orginal.SINumber = this.SINumber;
                //orginal.CommodityTypeID = this.CommodityTypeID;

                orginal.WayBillNo          = this.WayBillNo;
                orginal.ResponsibleDonorID = this.ResponsibleDonorID;
                orginal.SourceDonorID      = this.SourceDonorID;

                //orginal.ReceivedByStoreMan = this.ReceivedByStoreMan;
                //orginal.CommoditySourceID = this.CommoditySourceID;
                orginal.WeightBeforeUnloading = this.WeightBeforeUnloading;
                orginal.WeightAfterUnloading  = this.WeightAfterUnloading;
                orginal.Remark     = this.Remark;
                orginal.VesselName = this.VesselName;
                orginal.PortName   = this.PortName;
                orginal.WeightBridgeTicketNumber = this.WeightBridgeTicketNumber;


                foreach (BLL.ReceiveDetail insert in inserted)
                {
                    //TODO THIS should be in transaction
                    //orginal.ReceiveDetails.Add(insert);
                }

                foreach (BLL.ReceiveDetail delete in deleted)
                {
                    BLL.ReceiveDetail deletedCommodity = db.ReceiveDetails.SingleOrDefault(p => p.ReceiveDetailID == delete.ReceiveDetailID);
                    if (deletedCommodity != null)
                    {
                        //      db.ReceiveDetails.DeleteObject(deletedCommodity);
                    }
                }

                foreach (BLL.ReceiveDetail update in updated)
                {
                    BLL.ReceiveDetail updatedCommodity = db.ReceiveDetails.SingleOrDefault(p => p.ReceiveDetailID == update.ReceiveDetailID);
                    if (updatedCommodity != null)
                    {
                        //updatedCommodity.CommodityID = update.CommodityID;
                        updatedCommodity.Description = update.Description;
                        //updatedCommodity.ReceiveDetailID = update.ReceiveDetailID;
                        //updatedCommodity.SentQuantityInMT = update.SentQuantityInMT;
                        //updatedCommodity.ReceivedQuantityInMT = updatedCommodity.ReceivedQuantityInMT;
                        //updatedCommodity.SentQuantityInUnit = update.SentQuantityInUnit;
                        //updatedCommodity.UnitID = update.UnitID;
                    }
                }
                db.SaveChanges();
            }
        }
Exemple #22
0
        /// <summary>
        /// Gets the receive by GRN.
        /// </summary>
        /// <param name="grnNo">The GRN no.</param>
        /// <returns></returns>
        public static Receive GetReceiveByGRN(string grnNo)
        {
            CTSContext entities = new CTSContext();

            return(entities.Receives.FirstOrDefault(p => p.GRN == grnNo));
        }
 //TODO: remove the context here.
 public override string GetUserNameByEmail(string email)
 {
     var entities = new CTSContext() ;
     UserProfile user = (from u in entities.UserProfiles
                         where u.Email == email
                         select u).SingleOrDefault();
     return user.UserName;
 }
 // TODO: Remove the context here.
 public override bool ValidateUser(string username, string password)
 {
     var entities = new CTSContext();
     string pass = MD5Hashing.MD5Hash(password);
     UserProfile user = (from u in entities.UserProfiles
                         where u.UserName == username && u.Password == pass &&
                               !u.LockedInInd && u.ActiveInd
                         select u).SingleOrDefault();
     return (user != null) ? true : false;
 }
        public override bool ChangePassword(string username, string oldPassword, string newPassword)
        {
            if (ValidateUser(username, oldPassword))
            {
                var context = new CTSContext();
                UserProfile user = context.UserProfiles.Where(p => p.UserName == username).SingleOrDefault();
                if (user != null)
                {
                    user.Password = MD5Hashing.MD5Hash(newPassword);
                    context.SaveChanges();
                    return true;
                }
            }

            return false;
        }
Exemple #26
0
 public static void AddRole(Role role)
 {
     CTSContext entities = new CTSContext();
     entities.Roles.Add(role);
     entities.SaveChanges();
 }
Exemple #27
0
 public static Role GetRole(string name)
 {
     CTSContext entities = new CTSContext();
     return entities.Roles.Where(p => p.Name == name).SingleOrDefault();
     ;
 }
 public UnitOfWork()
 {
     _context= new CTSContext();
 }
Exemple #29
0
 public static bool RoleExists(string name)
 {
     CTSContext entities = new CTSContext();
     var count = entities.Roles.Where(p => p.Name == name).Count();
     return (count > 0);
 }
Exemple #30
0
 /// <summary>
 /// Gets the receive by GRN.
 /// </summary>
 /// <param name="grnNo">The GRN no.</param>
 /// <returns></returns>
 public static Receive GetReceiveByGRN(string grnNo)
 {
     CTSContext entities = new CTSContext();
     return entities.Receives.FirstOrDefault(p => p.GRN == grnNo);
 }
Exemple #31
0
        /// <summary>
        /// Updates the specified inserted.
        /// </summary>
        /// <param name="inserted">The inserted.</param>
        /// <param name="updated">The updated.</param>
        /// <param name="deleted">The deleted.</param>
        public void Update(List<BLL.ReceiveDetail> inserted, List<BLL.ReceiveDetail> updated,
            List<BLL.ReceiveDetail> deleted)
        {
            CTSContext db = new CTSContext();
            BLL.Receive orginal = db.Receives.SingleOrDefault(p => p.ReceiveID == this.ReceiveID);
            if (orginal != null)
            {

                // CreatedDate = DateTime.Now,
                orginal.ReceiptDate = this.ReceiptDate;
                // orginal.ReceiveID = this.ReceiveID;
                orginal.DriverName = this.DriverName;
                orginal.GRN = this.GRN;
                orginal.PlateNo_Prime = this.PlateNo_Prime;
                orginal.PlateNo_Trailer = this.PlateNo_Trailer;
                //orginal.StackNumber = this.StackNumber;
                orginal.TransporterID = this.TransporterID;
                orginal.HubID = this.HubID;
               // orginal.SINumber = this.SINumber;
                //orginal.CommodityTypeID = this.CommodityTypeID;

                orginal.WayBillNo = this.WayBillNo;
                orginal.ResponsibleDonorID = this.ResponsibleDonorID;
                orginal.SourceDonorID = this.SourceDonorID;

                //orginal.ReceivedByStoreMan = this.ReceivedByStoreMan;
                //orginal.CommoditySourceID = this.CommoditySourceID;
                orginal.WeightBeforeUnloading = this.WeightBeforeUnloading;
                orginal.WeightAfterUnloading = this.WeightAfterUnloading;
                orginal.Remark = this.Remark;
                orginal.VesselName = this.VesselName;
                orginal.PortName = this.PortName;
                orginal.WeightBridgeTicketNumber = this.WeightBridgeTicketNumber;

                foreach (BLL.ReceiveDetail insert in inserted)
                {
                    //TODO THIS should be in transaction
                    //orginal.ReceiveDetails.Add(insert);
                }

                foreach (BLL.ReceiveDetail delete in deleted)
                {
                    BLL.ReceiveDetail deletedCommodity = db.ReceiveDetails.SingleOrDefault(p => p.ReceiveDetailID == delete.ReceiveDetailID);
                    if (deletedCommodity != null)
                    {
                  //      db.ReceiveDetails.DeleteObject(deletedCommodity);
                    }
                }

                foreach (BLL.ReceiveDetail update in updated)
                {
                    BLL.ReceiveDetail updatedCommodity = db.ReceiveDetails.SingleOrDefault(p => p.ReceiveDetailID == update.ReceiveDetailID);
                    if (updatedCommodity != null)
                    {
                        //updatedCommodity.CommodityID = update.CommodityID;
                        updatedCommodity.Description = update.Description;
                        //updatedCommodity.ReceiveDetailID = update.ReceiveDetailID;
                        //updatedCommodity.SentQuantityInMT = update.SentQuantityInMT;
                        //updatedCommodity.ReceivedQuantityInMT = updatedCommodity.ReceivedQuantityInMT;
                        //updatedCommodity.SentQuantityInUnit = update.SentQuantityInUnit;
                        //updatedCommodity.UnitID = update.UnitID;
                    }
                }
                db.SaveChanges();
            }
        }
Exemple #32
0
 /// <summary>
 /// Determines whether the specified id has updated.
 /// </summary>
 /// <param name="id">The id.</param>
 /// <param name="table">The table.</param>
 /// <param name="property">The property.</param>
 /// <returns>
 ///   <c>true</c> if the specified id has updated; otherwise, <c>false</c>.
 /// </returns>
 public static bool HasUpdated(object id, string table, string property)
 {
     if(id != null)
     {
         string stringId = id.ToString();
         CTSContext db = new CTSContext();
         var count = (from audit in db.Audits
                      where audit.TableName == table && audit.PrimaryKey.Equals(stringId) && audit.NewValue.Contains(property)
                      select audit).Count();
         return (count > 0);
     }
     return false;
 }
Exemple #33
0
 public UnitOfWork()
 {
     _context = new CTSContext();
 }
Exemple #34
0
 /// <summary>
 /// Determines whether the specified id has updated.
 /// </summary>
 /// <param name="id">The id.</param>
 /// <param name="table">The table.</param>
 /// <returns>
 ///   <c>true</c> if the specified id has updated; otherwise, <c>false</c>.
 /// </returns>
 public static bool HasUpdated(int id, string table)
 {
     CTSContext db = new CTSContext();
     var count = (from audit in db.Audits
                  where audit.TableName == table && audit.PrimaryKey == id.ToString()
                  select audit).Count();
     return (count > 0);
 }