예제 #1
0
        protected void btnSave_Click(object sender, EventArgs e)
        {
            using (Medical_Clinic_Entities mc = new Medical_Clinic_Entities())
            {
                foreach (RepeaterItem item in rptService.Items)
                {
                    var chkService = ((CheckBox)item.FindControl("chkService"));
                    int serviceId = int.Parse(((Label)item.FindControl("lblId")).Text);
                    short minsForService = short.Parse(((TextBox)item.FindControl("txtMinsForService")).Text);
                    var txtPortion = ((TextBox)item.FindControl("txtPortion"));

                    var employeeId = Request["ID"];
                    var currentEmployeeService = mc.BSI__Employee_Service_Set.Where(o => o.Employee_Id == employeeId && o.Service_Id == serviceId).ToList();

                    if (chkService.Checked == true && chkService.Enabled == true)
                    {
                        if (currentEmployeeService.Count() == 0)
                        {
                            BSI__Employee_Service employeeService = new BSI__Employee_Service();
                            employeeService.Service_Id = serviceId;
                            employeeService.Employee_Id = employeeId;
                            employeeService.Mins_For_Service = minsForService;

                            mc.BSI__Employee_Service_Set.Add(employeeService);
                            addPart(employeeService.Service_Id, employeeId);
                        }
                        else
                        {
                            currentEmployeeService.First().Mins_For_Service = minsForService;
                            editPart(currentEmployeeService.First().Service_Id, employeeId);
                        }
                    }
                    else if(chkService.Enabled == true)
                    {
                        if (currentEmployeeService.Count() != 0)
                        {
                            mc.BSI__Employee_Service_Set.Remove(currentEmployeeService.First());
                            deletePart(currentEmployeeService.First().Service_Id, employeeId);
                        }
                    }
                }

                mc.SaveChanges();
            }
        }
예제 #2
0
        private void addPart(int? parentServiceId, string employeeId)
        {
            using (Medical_Clinic_Entities mc = new Medical_Clinic_Entities())
            {
                var parts = mc.BSI__Clinic_Services.Where(o => o.Parent_Id == parentServiceId && o.Is_Part == true).ToList();
                if (parts.Count() != 0)
                {
                    foreach (RepeaterItem item in rptService.Items)
                    {
                        int serviceId = int.Parse(((Label)item.FindControl("lblId")).Text);

                        if (parts.Where(o => o.Id == serviceId).Count() != 0)
                        {
                            short minsForService = short.Parse(((TextBox)item.FindControl("txtMinsForService")).Text);

                            var employeePart = new BSI__Employee_Service();
                            employeePart.Employee_Id = employeeId;
                            employeePart.Service_Id = serviceId;
                            employeePart.Mins_For_Service = minsForService;
                            mc.BSI__Employee_Service_Set.Add(employeePart);
                        }
                    }

                    mc.SaveChanges();
                }
            }
        }
        private void addNewPartToEmployeesOfService(Medical_Clinic_Entities mc, int partId, int serviceId)
        {
            var allEmployeesOfService = mc.BSI__Employee_Service_Set.Where(o => o.Service_Id == serviceId).ToList();
            if (allEmployeesOfService.Count != 0)
            {
                var allEmployees = allEmployeesOfService.Select(o => o.BSI__Clinic_Employees).Distinct().ToList();

                foreach (var employee in allEmployees)
                {
                    var employeeService = new BSI__Employee_Service();
                    employeeService.Mins_For_Service = 0;
                    employeeService.Employee_Id = employee.Id;
                    employeeService.Service_Id = partId;
                    mc.BSI__Employee_Service_Set.Add(employeeService);
                }
            }
        }