Click here to Skip to main content
15,887,683 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
C#
public class DashboardWorkQueue : System.Web.Services.WebService
    {
        private IErrorHandling _IErrorHandling;
        private IServiceHandler.Notification.ISubscription _ISubscription;
        private INotificationLeadTime _INotificationLeadTime;
        private IServiceHandler.Audit.IAuditNote _IAuditNote;

        public DashboardWorkQueue()
        {
            _IErrorHandling = new ErrorHandling();

            var container = new StructureMap.Container(new Service.Infrastructure.StructureMapRegistry());
           
            _ISubscription = container.GetInstance<isubscription>();
            _INotificationLeadTime = new Service.Notification.NotificationLeadTime();
            _IAuditNote = container.GetInstance<iservicehandler.audit.iauditnote>();
        }

        [WebMethod]
        public int EnableDisable(Guid userID, int recordID, Model.SubscriptionSource.SubscriptionSourceEnum subscriptionSourceEnum, bool enabled)
        {
            int subscriptionID = 0;

            try
            {
                subscriptionID = Systrends.TMS.Business.ServiceHandler.DashboardWorkQueue.EnableOrDisable(userID, recordID, subscriptionSourceEnum, enabled);
            }
            catch (Exception ex)
            {
                _IErrorHandling.LogErrorNoRedirect(ex);
                throw;
            }

            return subscriptionID;
        }

        [WebMethod]
        public int Enabled(Guid userID, int recordID, Model.SubscriptionSource.SubscriptionSourceEnum subscriptionSourceEnum)
        {
            Model.Subscription subscriptionModel = new Model.Subscription();

            int subscriptionID = 0;

            try
            {
                subscriptionModel = _ISubscription.Get(userID, recordID, subscriptionSourceEnum, Model.SubscriptionOrigination.SubscriptionOriginationEnum.UserSubscription);

                if (subscriptionModel == null)
                    return 0;

                if (subscriptionModel.DesktopLink.HasValue)
                {
                    if (subscriptionModel.DesktopLink.Value == true)
                        subscriptionID = subscriptionModel.Id;
                }
            }
            catch (Exception ex)
            {
                _IErrorHandling.LogErrorNoRedirect(ex);
                throw;
            }

            return subscriptionID;
        }

        [WebMethod]
        public void Save(int taskID, int subscriptionID, string note, Guid userID, DateTime dateDue, int filingId)
        {
            Systrends.TMS.Business.ServiceHandler.Notification notification = new Notification();

            try
            {
                if (taskID == 0)
                {
                    taskID = Systrends.TMS.Business.ServiceHandler.Task.Insert(subscriptionID, note, userID, dateDue);
                    notification.CreateTaskNotification(subscriptionID, taskID, dateDue, userID);
                    AddAuditNote(filingId, userID, "", "Insert");
                }
                else
                {
                     Systrends.TMS.Business.ServiceHandler.Task.Update(taskID, note, userID, dateDue);
                     notification.CreateTaskNotification(subscriptionID, taskID, dateDue, userID);
                     AddAuditNote(filingId, userID, "", "Update");
                                         
                }
            }
            catch (Exception ex)
            {
                _IErrorHandling.LogErrorNoRedirect(ex);
                throw;
            }
        }

        [WebMethod]
        public List<Model.Task> GetList(int subscriptionID)
        {
            try
            {
                <Model.Task> list = Task.GetList(subscriptionID);

                return list;
            }
            catch (Exception ex)
            {
                _IErrorHandling.LogErrorNoRedirect(ex);
                throw;
            }
        }

        [WebMethod]
        public Model.Task Get(int taskID)
        {
            try
            {

                Model.Task model = Task.Get(taskID);

                return model;
            }
            catch (Exception ex)
            {
                _IErrorHandling.LogErrorNoRedirect(ex);
                throw;
            }
        }


        [WebMethod]
        public void DeleteTask(int taskID,int filingId,Guid userId)
        {
            try
            {
                Model.Users user = SessionWrapper.UserModel;

                Systrends.TMS.Business.ServiceHandler.Task.Delete_ById(taskID);
                if (Guid.Empty != userId)
                {
                    AddAuditNote(filingId, userId, "", "Delete");
                }
               
            }
            catch (Exception ex)
            {
                _IErrorHandling.LogErrorNoRedirect(ex);
                throw;
            }
        }

        private void AddAuditNote(int filingId, Guid userId, string createdBy, string changeBy)
        {
            string message = null;
            if (userId == Guid.Empty)
            {
                Systrends.TMS.Data.User_View userView = RepositoryEF.User.UserRepository.Get_ByUserName(createdBy);
                userId = userView.UserId;
            }
            switch (changeBy)
            {
                case "Insert":
                    message = "Inserted Work Queue note";
                    break;
                case "Update":
                    message = "Updated Work Queue note";
                    break;
                case "Delete":
                    message = "Deleted Work Queue note";
                    break;
                default:
                    break;
            }
            if (string.IsNullOrEmpty(message))
            {
                message = changeBy;
            }
            _IAuditNote.Insert(Model.AuditNote.EntityType.Filing, filingId, userId, message);
        }

    }
}
Posted
Updated 15-Dec-14 3:41am
v4
Comments
ZurdoDev 15-Dec-14 7:41am    
What is the error?
Tejas Vaishnav 15-Dec-14 9:13am    
What exception your got? can your please improve your question and add more detail like on which line your got exception and also add exception details too.
Tomas Takac 15-Dec-14 9:43am    
Did you put any effort in debuggig this? Where does the error occure? My guess is in AddAuditNote method. Please show the relevant code.

1 solution

This Error telling that When you are inserting value in some column which is referenced from another table, the value is not contained by Reference table.

Let me Give you an Example...

Say I have table "Project" and it have column IndustryID referenced to another table Industry.

Industry
ID Name
--------------------
1 Healthcare
2 Auto Mobile
3 Real Estate

Project
ID Name IndustryID
-------------------------------
1 P1 2
2 P2 3

Now if i do something like this...
insert into Project values(3,P3,10)

This will give me an error that insert statement conflicted with foreign key.
because there is no record having ID=10 in Industry table and i am trying to insert it in Project table which is referenced to Industry.

Hope you understand the actual problem and this might help you to solve your Problem.

EDIT :
the value you want to add into a table which consist of foreign key,the reference table must contain this value.(So insert that value first in Reference table and then in your table where it has been referenced).
 
Share this answer
 
v2
Comments
CP_vicky 16-Dec-14 1:19am    
What i understand is if we want to add a new row into a table which consist of Foreign key that should not allow, we need to add in to the table first which consist of primary key. is it correct.
Pratik Bhuva 5-Jan-15 10:15am    
correct.
the value you want to add into a table which consist of foreign key,the reference table must contain this value.(So insert that value first in Reference table and then in your table where it has been referenced).
TheRealSteveJudge 5-Jan-15 10:31am    
5*
Pratik Bhuva 6-Jan-15 4:25am    
Thanks :)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900