Esempio n. 1
0
        public async Task <IActionResult> Edit(int id, [Bind("ID,CompanyDepartmentName")] CompanyDepartments companyDepartments)
        {
            if (id != companyDepartments.ID)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    companyDepartments.CompanyID = HttpContext.Session.GetInt32("CompanyID") ?? 0;
                    _context.Update(companyDepartments);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!CompanyDepartmentsExists(companyDepartments.ID))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(companyDepartments));
        }
        protected override void OnClearCommand()
        {
            try
            {
                UpdateViewState(Edit.Mode.Adding);
                Model = new CompanyDepartmentJobRole();

                if (Companies != null)
                {
                    Companies.MoveCurrentToFirst();
                }
                if (CompanyDepartments != null)
                {
                    CompanyDepartments.MoveCurrentToFirst();
                }
                if (JobRoles != null)
                {
                    JobRoles.MoveCurrentToFirst();
                }
            }
            catch (Exception ex)
            {
                Utility.DisplayMessage(ex.Message);
            }
        }
Esempio n. 3
0
        public async Task <IActionResult> Create([Bind("ID,CompanyDepartmentName")] CompanyDepartments companyDepartments)
        {
            if (ModelState.IsValid)
            {
                companyDepartments.CompanyID = HttpContext.Session.GetInt32("CompanyID") ?? 0;
                _context.Add(companyDepartments);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(companyDepartments));
        }
        //protected override void LoadAllCommandCompletedHelper()
        //{
        //    try
        //    {
        //        dispatcher.BeginInvoke
        //                   (() =>
        //                   {
        //                       if (Utility.FaultExist(companyDepartmentJobRoleService.Fault))
        //                       {
        //                           return;
        //                       }

        //                       Models = new PagedCollectionView(companyDepartmentJobRoleService.Models);
        //                       if (companyDepartmentJobRoleService.Models != null && companyDepartmentJobRoleService.Models.Count > 0)
        //                       {
        //                           RecordCount = RecordCountLabel + companyDepartmentJobRoleService.Models.Count;
        //                           Models.MoveCurrentTo(null);
        //                           Models.CurrentChanged += (s, e) =>
        //                           {
        //                               SetSelectedModel();
        //                           };
        //                       }
        //                       else
        //                       {
        //                           RecordCount = RecordCountLabel + 0;
        //                       }
        //                   });
        //    }
        //    catch (Exception ex)
        //    {
        //        Utility.DisplayMessage(ex.Message);
        //    }
        //}


        protected override void SetSelectedModel()
        {
            try
            {
                if (Models != null)
                {
                    Model = Models.CurrentItem as CompanyDepartmentJobRole;

                    if (Model != null)
                    {
                        //if (Companies != null)
                        //{
                        //    ObservableCollection<Company> companies = (ObservableCollection<Company>)Companies.SourceCollection;
                        //    Company company = companies.Where(c => c.Id == Model.Company.Id).SingleOrDefault();
                        //    if (company != null)
                        //    {
                        //        Companies.MoveCurrentTo(company);
                        //    }
                        //}

                        if (CompanyDepartments != null)
                        {
                            ObservableCollection <CompanyDepartment> departments = (ObservableCollection <CompanyDepartment>)CompanyDepartments.SourceCollection;
                            CompanyDepartment department = departments.Where(d => d.Department.Id == Model.Department.Id && d.Company.Id == Model.Company.Id).SingleOrDefault();
                            if (department != null)
                            {
                                CompanyDepartments.MoveCurrentTo(department);
                            }
                        }

                        if (JobRoles != null)
                        {
                            ObservableCollection <JobRole> jobRoles = (ObservableCollection <JobRole>)JobRoles.SourceCollection;
                            JobRole jobRole = jobRoles.Where(d => d.Id == Model.JobRole.Id).SingleOrDefault();
                            if (jobRole != null)
                            {
                                JobRoles.MoveCurrentTo(jobRole);
                            }
                        }
                    }

                    UpdateViewState(Edit.Mode.Editing);
                }
            }
            catch (Exception ex)
            {
                Utility.DisplayMessage(ex.Message);
            }
        }
Esempio n. 5
0
        public static void UpdateBranchDetails()
        {
            using (var db = new MasterContext())
            {
                CompanyDepartments department = new CompanyDepartments();
                Console.WriteLine("Enter the Department Name which you want to update");
                department.DepartmentName = Console.ReadLine();

                CompanyDepartments c = db.CompanyDepartments.Single(t => t.DepartmentName == department.DepartmentName);
                if (c != null)
                {
                    Console.WriteLine("Enter the Department Name which you want");
                    c.DepartmentName = Console.ReadLine();
                    db.SaveChanges();
                    Console.WriteLine("Department Name is Modified");
                }
                else
                {
                    Console.WriteLine("You enter Wrong Department Name which you want to update");
                }
            }
        }
Esempio n. 6
0
 public static void DeleteBranchDetails()
 {
     using (var db = new MasterContext())
     {
         var department = new CompanyDepartments();
         {
             Console.WriteLine("Enter Department Id");
             department.DepartmentId = Convert.ToInt32(Console.ReadLine());
             var check = db.CompanyDepartments.Where(t => t.DepartmentId == department.DepartmentId);
             if (check != null)
             {
                 db.CompanyDepartments.Remove(department);
                 db.SaveChanges();
                 Console.WriteLine("Department Details is successfully Deleted!!");
             }
             else
             {
                 Console.WriteLine("No Department is Existing of this Id!!");
             }
         }
     }
 }
Esempio n. 7
0
        public async Task <bool> AddDepartmentToCompany(int companyId, int departmentId)
        {
            var existingCompanyDepartment = await this.dbContext.CompanyDepartments
                                            .FirstOrDefaultAsync(cd => cd.CompanyId == companyId && cd.DepartmentId == departmentId);

            if (existingCompanyDepartment != null)
            {
                return(false);
            }

            var companyDepartment = new CompanyDepartments
            {
                CompanyId    = companyId,
                DepartmentId = departmentId
            };

            this.dbContext.CompanyDepartments
            .Add(companyDepartment);

            await this.dbContext.SaveChangesAsync();

            return(true);
        }
Esempio n. 8
0
        public static void AddBranchDetails()
        {
            using (var db = new MasterContext())
            {
                var department = new CompanyDepartments();
                {
                    Console.WriteLine("Enter Company Name");
                    string companyName = Console.ReadLine();

                    Console.WriteLine("Enter Company Location");
                    string companyLocation = Console.ReadLine();


                    var get = db.Company.First(t => t.CompanyName == companyName && t.CompanyLocation == companyLocation);
                    if (get != null)
                    {
                        department.CompanyId = get.CompanyId;
                    }

                    Console.WriteLine("Enter Department Name");
                    department.DepartmentName = Console.ReadLine();

                    var check = db.CompanyDepartments.Where(t => t.DepartmentName == department.DepartmentName);
                    if (check != null)
                    {
                        Console.WriteLine("This Department is Existing!!");
                    }
                    else
                    {
                        db.CompanyDepartments.Add(department);
                        db.SaveChanges();
                        Console.WriteLine("Department Information is Successfully added!!");
                    }
                }
            }
        }
Esempio n. 9
0
        public string GetCompanyDepartmentName(string DepartmentID)
        {
            CompanyDepartments cd = _context.CompanyDepartments.AsNoTracking().FirstOrDefault(n => n.ID.ToString() == DepartmentID);

            return(cd.CompanyDepartmentName);
        }
Esempio n. 10
0
        /// <summary>
        /// Gets the Company Details based on the CompanyID
        /// </summary>
        private void GetCompany()
        {
            try
            {
                Database  db         = DatabaseFactory.CreateDatabase(_myConnection.DatabaseName);
                string    sqlCommand = "spGetCompany";
                DbCommand dbCommand  = db.GetStoredProcCommand(sqlCommand);
                db.AddInParameter(dbCommand, "CompanyID", DbType.Int32, CompanyID);
                DataSet ds = db.ExecuteDataSet(dbCommand);

                // Load Company Info
                if (ds.Tables[0].Rows.Count > 0)
                {
                    DataRow dRow = ds.Tables[0].Rows[0];
                    CompanyName    = Common.CheckNull(dRow["CompanyName"]);
                    CompanyEstCode = dRow["CompanyEst_Code"].ToString();
                    CompanyEstExtn = dRow["CompanyEst_Extn"].ToString();

                    CompanyShortCode               = Common.CheckNull(dRow["CompanyShortCode"]);
                    CompanyAddress.Address1        = Common.CheckNull(dRow["Address1"]);
                    CompanyAddress.Address2        = Common.CheckNull(dRow["Address2"]);
                    CompanyAddress.Address3        = Common.CheckNull(dRow["Address3"]);
                    CompanyAddress.CityDescription = Common.CheckNull(dRow["City"]);
                    CompanyAddress.StateID         = Common.CheckIntNull(dRow["StateID"]);
                    CompanyAddress.StateName       = Common.CheckNull(dRow["StateName"]);
                    CompanyAddress.CountryID       = Common.CheckIntNull(dRow["CountryID"]);
                    CompanyAddress.CountryName     = Common.CheckNull(dRow["CountryName"]);
                    CompanyAddress.PostalCode      = Common.CheckNull(dRow["PostalCode"]);
                    Phone1      = Common.CheckNull(dRow["Phone1"]);
                    Phone2      = Common.CheckNull(dRow["Phone2"]);
                    Fax         = Common.CheckNull(dRow["Fax"]);
                    WebSite     = Common.CheckNull(dRow["WebSite"]);
                    Comments    = Common.CheckNull(dRow["Comments"]);
                    AuditUserID = Common.CheckIntNull(dRow["AuditUserID"]);
                    if (dRow["AuditDate"] != DBNull.Value)
                    {
                        AuditDate = Convert.ToDateTime(dRow["AuditDate"]);
                    }
                    else
                    {
                        AuditDate = null;
                    }
                }

                // Load Company Departments
                DepartmentDL cDepartment;
                foreach (DataRow dRow in ds.Tables[1].Rows)
                {
                    cDepartment = new DepartmentDL();
                    cDepartment.DepartmentID          = Common.CheckIntNull(dRow["DepartmentID"]);
                    cDepartment.DepartmentDescription = Common.CheckNull(dRow["DepartmentDescription"]);
                    cDepartment.CompanyID             = Common.CheckIntNull(dRow["CompanyID"]);

                    CompanyDepartments.Add(cDepartment);
                }
            }
            catch (Exception ex)
            {
                ErrorLog.LogErrorMessageToDB("", "CompanyDL.cs", "GetCompany", ex.Message, _myConnection);
                throw;
            }
        }