Пример #1
0
        public ServiceENT CreateSingle(ServiceENT Obj)
        {
            if (Obj.ServiceChargedAs == 1)
            {
                Obj.Rate = Obj.Rate;
            }
            else
            {
                Obj.Rate = "0";
            }
            if (Obj.ServiceChargedAs == 2)
            {
                //Add Service rates per slabs
                AddServiceRateSlabsList(Obj.Id, Obj.ServicePerSlabList);
            }

            NbkDbEntities dbcontext = new NbkDbEntities();
            Service       Data      = new Service()
            {
                Name             = Obj.Name,
                Description      = Obj.Description,
                ServiceTypeId    = Obj.ServiceTypeId,
                ServiceChargedAs = Obj.ServiceChargedAs,
                Rate             = Obj.Rate
            };


            dbcontext.Service.Add(Data);
            dbcontext.SaveChanges();

            Obj.Id = Data.Id;
            Obj.ServiceWorkflowCategory.ForEach(x => x.ServiceId = Obj.Id);
            //Adding service workflow
            foreach (var item in Obj.ServiceWorkflowCategory)
            {
                dbcontext = new NbkDbEntities();
                ServiceWorkflowCategory ServiceData = new ServiceWorkflowCategory()
                {
                    ServiceId          = item.ServiceId,
                    WorkflowCategoryId = item.WorkflowCategoryId
                };
                dbcontext.ServiceWorkflowCategory.Add(ServiceData);
                dbcontext.SaveChanges();
                item.Id = ServiceData.Id;
            }


            return(Obj);
        }
Пример #2
0
        public ServiceENT UpdateSelectSingle(ServiceENT Obj)
        {
            if (Obj.ServiceChargedAs == 1)
            {
                Obj.Rate = Obj.Rate;
            }
            else
            {
                Obj.Rate = "0";
            }
            new ServiceCRUD().DeleteSlabService(Obj.Id);
            if (Obj.ServiceChargedAs == 2)
            {
                //Add Service rates per slabs
                AddServiceRateSlabsList(Obj.Id, Obj.ServicePerSlabList);
            }

            NbkDbEntities dbcontext = new NbkDbEntities();
            Service       Data      = new Service()
            {
                Id               = Obj.Id,
                Name             = Obj.Name,
                Description      = Obj.Description,
                ServiceTypeId    = Obj.ServiceTypeId,
                ServiceChargedAs = Obj.ServiceChargedAs,
                Rate             = Obj.Rate
            };


            dbcontext.Service.Attach(Data);
            var update = dbcontext.Entry(Data);

            update.Property(x => x.Name).IsModified             = true;
            update.Property(x => x.Description).IsModified      = true;
            update.Property(x => x.ServiceTypeId).IsModified    = true;
            update.Property(x => x.ServiceChargedAs).IsModified = true;
            update.Property(x => x.Rate).IsModified             = true;

            dbcontext.SaveChanges();

            //Check for new workflow to be added
            //Delete Previous ServiceWorkflows
            if (Obj.ServiceWorkflowCategory != null)
            {
                DeleteServiceWorkflowCategoryByServiceID(Obj.Id);
            }
            //Adding service workflow
            foreach (var item in Obj.ServiceWorkflowCategory)
            {
                dbcontext = new NbkDbEntities();
                ServiceWorkflowCategory ServiceData = new ServiceWorkflowCategory()
                {
                    ServiceId          = item.ServiceId,
                    WorkflowCategoryId = item.WorkflowCategoryId
                };
                dbcontext.ServiceWorkflowCategory.Add(ServiceData);
                dbcontext.SaveChanges();
                item.Id = ServiceData.Id;
            }

            return(Obj);
        }