Example #1
0
        // Calling the method of using Async
        //public  int test() {
        //    int task =  Insert().Result;
        //    return task;

        //}
        public int InsertTask(Hr_Cities objInsert)
        {
            StackFrame stackFrame = new StackFrame();
            MethodBase methodBase = stackFrame.GetMethod();

            //int result = Insert(objInsert).Result;
            //return result;

            int RowEffected = 0;

            try
            {
                if (objInsert != null)
                {
                    OpenEntityConnection();
                    objInsert.InsDate = DateTime.Now;//DateTime.Today;


                    objPharmaEntities.Hr_Cities.Add(objInsert);
                    RowEffected = objPharmaEntities.SaveChanges();
                }
            }
            catch (Exception ex)
            {
                catchEntityvalidation((System.Data.Entity.Validation.DbEntityValidationException)ex, System.Runtime.InteropServices.Marshal.GetExceptionCode().ToString(),
                                      this.UserNameProperty.ToString(), this.GetType().Name.ToString(), methodBase.Name.ToString());
                RowEffected = -1;
                ex.InnerException.Message.ToString();
            }
            finally
            {
                CloseEntityConnection();
            }
            return(RowEffected);
        }
Example #2
0
        public Hr_Cities GetById(string City_ID)
        {
            StackFrame stackFrame = new StackFrame();
            MethodBase methodBase = stackFrame.GetMethod();

            try
            {
                OpenEntityConnection();
                Hr_Cities CitiesForGetEntity = (from objLinq in objPharmaEntities.Hr_Cities
                                                where objLinq.City_Id == City_ID && objLinq.Rec_Status == 0
                                                select objLinq).FirstOrDefault();
                return(CitiesForGetEntity);
            }
            catch (Exception ex)
            {
                catchEntityvalidation((System.Data.Entity.Validation.DbEntityValidationException)ex, System.Runtime.InteropServices.Marshal.GetExceptionCode().ToString(),
                                      this.UserNameProperty.ToString(), this.GetType().Name.ToString(), methodBase.Name.ToString());
                ex.InnerException.Message.ToString();
                return(null);
            }
            finally
            {
                CloseEntityConnection();
            }
        }
Example #3
0
        public bool UpdateTask(Hr_Cities objUpdate)
        {
            StackFrame stackFrame = new StackFrame();
            MethodBase methodBase = stackFrame.GetMethod();

            // bool task = Update(objInsert).Result;
            //return task;
            int rowEffected = 0;

            try
            {
                if (objUpdate != null) //Definsive Programming
                {
                    OpenEntityConnection();
                    Hr_Cities ObjForUpdate = (from objLinq in objPharmaEntities.Hr_Cities
                                              where objLinq.City_Id == objUpdate.City_Id
                                              select objLinq).FirstOrDefault();
                    ObjForUpdate.City_Name   = objUpdate.City_Name;
                    ObjForUpdate.City_NameEn = objUpdate.City_NameEn;
                    ObjForUpdate.Country_Id  = objUpdate.Country_Id;
                    ObjForUpdate.City_Code   = objUpdate.City_Code;
                    ObjForUpdate.UpdateUser  = objUpdate.UpdateUser;
                    ObjForUpdate.UpdateDate  = DateTime.Now;

                    rowEffected = objPharmaEntities.SaveChanges();
                }
            }
            catch (Exception ex)
            {
                catchEntityvalidation((System.Data.Entity.Validation.DbEntityValidationException)ex, System.Runtime.InteropServices.Marshal.GetExceptionCode().ToString(),
                                      this.UserNameProperty.ToString(), this.GetType().Name.ToString(), methodBase.Name.ToString());
                rowEffected = -1;
                ex.InnerException.Message.ToString();
            }
            finally
            {
                CloseEntityConnection();
            }
            if (rowEffected > 0)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
Example #4
0
        public async Task <bool> Delete(Hr_Cities objDelete)
        {
            StackFrame stackFrame = new StackFrame();
            MethodBase methodBase = stackFrame.GetMethod();

            int rowEffected = 0;

            try
            {
                if (objDelete != null) //Definsive Programming
                {
                    OpenEntityConnection();
                    Hr_Cities objForDelete = (from objLinq in objPharmaEntities.Hr_Cities
                                              where objLinq.City_Id == objDelete.City_Id
                                              select objLinq).FirstOrDefault();
                    objForDelete.Rec_Status = 1;
                    objForDelete.DeleteUser = objDelete.DeleteUser;
                    objForDelete.DeleteDate = DateTime.Now;

                    rowEffected = await objPharmaEntities.SaveChangesAsync();
                }
            }
            catch (Exception ex)
            {
                catchEntityvalidation((System.Data.Entity.Validation.DbEntityValidationException)ex, System.Runtime.InteropServices.Marshal.GetExceptionCode().ToString(),
                                      this.UserNameProperty.ToString(), this.GetType().Name.ToString(), methodBase.Name.ToString());
                rowEffected = -1;
                ex.InnerException.Message.ToString();
            }
            finally
            {
                CloseEntityConnection();
            }
            if (rowEffected > 0)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
Example #5
0
        public List <Hr_Cities> GetAll()
        {
            StackFrame stackFrame = new StackFrame();
            MethodBase methodBase = stackFrame.GetMethod();

            List <Hr_Cities> objlist = new List <Hr_Cities>();

            try
            {
                OpenEntityConnection();

                List <Hr_Cities> objectList = (from objLinq in objPharmaEntities.Hr_Cities
                                               where objLinq.Rec_Status == 0
                                               orderby objLinq.Id
                                               select objLinq).ToList();
                //City_Id,City_Name,City_NameEn,City_NameConv,Country_Id,City_Code,InsUser,InsDate,UpdateUser,UpdateDate,DeleteUser,DeleteDate,Rec_Status


                //string sql = "select *  from Hr_Cities where Rec_Status = 0  order by replicate('0',15-len(City_Id))+City_Id ";

                //List<Hr_Cities> objectlist = objPharmaEntities.Database.SqlQuery<Hr_Cities>(sql).ToList();



                if (objectList != null)
                {
                    foreach (var obj in objectList)
                    {
                        Hr_Cities obj1 = new Hr_Cities();
                        obj1.City_Id       = obj.City_Id;
                        obj1.City_Name     = obj.City_Name;
                        obj1.City_NameEn   = obj.City_NameEn;
                        obj1.City_NameConv = obj.City_NameConv;
                        obj1.Country_Id    = obj.Country_Id;
                        obj1.City_Code     = obj.City_Code;
                        objlist.Add(obj1);
                    }
                }

                return(objlist);
            }
            catch (System.Data.Entity.Validation.DbEntityValidationException ex)
            {
                Exception raise = ex;
                foreach (var validationErrors in ex.EntityValidationErrors)
                {
                    foreach (var validationError in validationErrors.ValidationErrors)
                    {
                        string message = string.Format("{0}:{1}",

                                                       validationErrors.Entry.Entity.ToString(),

                                                       validationError.ErrorMessage);

                        // raise a new exception nesting

                        // the current instance as InnerException

                        raise = new InvalidOperationException(message, raise);
                    }
                }

                throw raise;
            }
            catch (Exception ex)
            {
                catchEntityvalidation((System.Data.Entity.Validation.DbEntityValidationException)ex, System.Runtime.InteropServices.Marshal.GetExceptionCode().ToString(),
                                      this.UserNameProperty.ToString(), this.GetType().Name.ToString(), methodBase.Name.ToString());
                Exception raise = ex;



                ex.InnerException.Message.ToString();
                return(null);
            }
            finally
            {
                CloseEntityConnection();
            }
        }