public ActionResult Create([Bind(Include = "empLeaveAppID,empID,LeaveTypeID,LeaveReason,DateFiled,StartDate,EndDate,AppliedHours,ApprovedDate,ApprovedBy,IsApproved,IsWithPay,IsCancelled,Remarks,StampTime")] EmpLeaveApplication empLeaveApplication, string Create, string Edit)
        {
            EmployeeDD();
            LeaveTypeDD();
            SupervisorDD();
            var check           = empLeaveApplication.empLeaveAppID;
            var CheckAttendance = db.EmpLeaveApplications.FirstOrDefault(id => id.empLeaveAppID == empLeaveApplication.empLeaveAppID);

            if (ModelState.IsValid)
            {
                if (Create != null)
                {
                    if (CheckAttendance == null)
                    {
                        string conn = ConfigurationManager.ConnectionStrings["kalingaPPDO"].ConnectionString;
                        using (SqlConnection cn = new SqlConnection(conn))
                        {
                            SqlCommand cmd = cn.CreateCommand();
                            cmd.CommandText = "Execute sp_InsertEmpLeave @empID, @empAttendanceMainID, @LeaveTypeID, @LeaveReason, @DateFiled, @StartDate, @EndDate, @AppliedHours, @ApprovedDate, @ApprovedBy, @IsApproved, @IsWithPay, @IsCancelled, @Remarks";

                            cmd.Parameters.AddWithValue("@empID", empLeaveApplication.empID);
                            cmd.Parameters.AddWithValue("@empAttendanceMainID", empLeaveApplication.empAttendanceMainID.ToString());
                            cmd.Parameters.AddWithValue("@@attendancedetaildtrID", empLeaveApplication.AttendanceDetailDTRId.ToString());
                            cmd.Parameters.AddWithValue("@LeaveTypeID", empLeaveApplication.LeaveTypeID);
                            cmd.Parameters.AddWithValue("@LeaveReason", empLeaveApplication.LeaveReason);
                            cmd.Parameters.AddWithValue("@DateFiled", empLeaveApplication.DateFiled);
                            cmd.Parameters.AddWithValue("@StartDate", empLeaveApplication.StartDate);
                            cmd.Parameters.AddWithValue("@EndDate", empLeaveApplication.EndDate);
                            cmd.Parameters.AddWithValue("@AppliedHours", empLeaveApplication.AppliedHours);
                            cmd.Parameters.AddWithValue("@ApprovedDate", empLeaveApplication.ApprovedDate);
                            cmd.Parameters.AddWithValue("@ApprovedBy", empLeaveApplication.ApprovedBy);
                            cmd.Parameters.AddWithValue("@IsApproved", empLeaveApplication.IsApproved);
                            cmd.Parameters.AddWithValue("@IsWithPay", empLeaveApplication.IsWithPay);
                            cmd.Parameters.AddWithValue("@IsCancelled", empLeaveApplication.IsCancelled);
                            cmd.Parameters.AddWithValue("@Remarks", empLeaveApplication.Remarks);
                            cn.Open();
                            cmd.ExecuteNonQuery();
                            cn.Close();
                            return(RedirectToAction("Create"));
                        }
                    }
                    else
                    {
                        ModelState.AddModelError(string.Empty, "Leave Number " + empLeaveApplication.empLeaveAppID + " already exists. Please click update if you're trying to update a data.");
                        return(View(empLeaveApplication));
                    }
                }
                else if (Edit != null)
                {
                    db.Set <EmpLeaveApplication>().AddOrUpdate(empLeaveApplication);
                    db.SaveChanges();
                    return(RedirectToAction("Create"));
                }
            }
            return(View(empLeaveApplication));
        }
Exemple #2
0
        public ActionResult Create([Bind(Include = "empid,empNo,namePrefixTitleID,LastName,MiddleName,FirstName,nameSuffixTitleID,GenderID,ReligionID,street,BarangayID,MunicipalityID,ProvinceID,CountryID,zipCode,residentialPhoneNo,street2,BarangayID2,MunicipalityID2,ProvinceID2,CountryID2,zipCode2,residentialPhoneNo2,birthDate,birthPlace,CivilStatusID,CitizenshipID,Height,Weight,BloodTypeID,GSIS,HDMF,PhilHealth,SSS,TIN,LandLineNo,CellphoneNo,EmailAddress,YearsInService,MonthsInService,IsSupervisor,FirstApprover,SecondApprover,IsSeparated,DeptID,DepartmentUnitID,AppointmentStatusID,PositionID,DateHired,DateResigned,CurrentSalary,DisplayPicturePath,RegionID,RegionID2")] EmpMasterProfile empMasterProfile, HttpPostedFileBase File, string Create, string Edit, string empid)
        {
            CountryDD();
            BloodTypeDD();
            CitizenshipDD();
            CivilStatusDD();
            GenderDD();
            PrefixDD();
            ReligionDD();
            SuffixDD();
            SupervisorsDD();
            DepartmentDD();
            DepartmentUnitDD();
            AppointmentStatusDD();
            PositionDD();
            var EmployeeName        = empMasterProfile.FirstName + " " + empMasterProfile.MiddleName + " " + empMasterProfile.LastName;
            var EmployeeNameChecker = db.EmpMasterProfiles.FirstOrDefault(id => id.empid == empMasterProfile.empid);
            var EmpNameChecker      = db.EmpMasterProfiles.Any(name => name.FirstName + " " + name.MiddleName + " " + name.LastName == EmployeeName);

            //var FullNameCheck = EmployeeNameChecker.FirstName + " " + EmployeeNameChecker.MiddleName + " " + EmployeeNameChecker.LastName;
            if (ModelState.IsValid)
            {
                if (File != null)
                {
                    if ((File.ContentLength > 0 && empMasterProfile.DisplayPicturePath != null) || (File.ContentLength > 0 && empMasterProfile.DisplayPicturePath == null))
                    {
                        if ((Path.GetExtension(File.FileName).ToLower() == ".jpg") ||
                            (Path.GetExtension(File.FileName).ToLower() == ".jpeg") ||
                            (Path.GetExtension(File.FileName).ToLower() == ".png") ||
                            (Path.GetExtension(File.FileName).ToLower() == ".gif"))
                        {
                            WebImage img = new WebImage(File.InputStream);
                            if ((img.Width > 180) || (img.Height > 190))
                            {
                                img.Resize(190, 180);
                                string extension = Path.GetExtension(File.FileName);
                                string filename  = empMasterProfile.FirstName + empMasterProfile.MiddleName + empMasterProfile.LastName + DateTime.Now.ToString("MMddyy") + extension;
                                empMasterProfile.DisplayPicturePath = "~/Content/EmployeeProfileImages/" + filename;
                                img.Save(empMasterProfile.DisplayPicturePath);
                                filename = Path.Combine(Server.MapPath("~/Content/EmployeeProfileImages/"), filename);
                            }
                            else
                            {
                                string extension = Path.GetExtension(File.FileName);
                                string filename  = empMasterProfile.FirstName + empMasterProfile.MiddleName + empMasterProfile.LastName + DateTime.Now.ToString("MMddyy") + extension;
                                empMasterProfile.DisplayPicturePath = "~/Content/EmployeeProfileImages/" + filename;
                                filename = Path.Combine(Server.MapPath("~/Content/EmployeeProfileImages/"), filename);
                                File.SaveAs(filename);
                            }
                        }
                    }
                }
                else if (File == null && empMasterProfile.DisplayPicturePath == null)
                {
                    empMasterProfile.DisplayPicturePath = null;
                }
                if (Create != null)
                {
                    if (EmpNameChecker == false)
                    {
                        db.EmpMasterProfiles.Add(empMasterProfile);
                        db.SaveChanges();
                        return(RedirectToAction("Create"));
                    }
                    else
                    {
                        ModelState.AddModelError(string.Empty, "Employee " + EmployeeName + " has a saved data already! Please click update if you're trying to update a data.");
                        return(View(empMasterProfile));
                    }
                }
                else if (Edit != null)
                {
                    db.Set <EmpMasterProfile>().AddOrUpdate(empMasterProfile);
                    db.SaveChanges();
                    return(RedirectToAction("Create"));
                }
            }
            return(View(empMasterProfile));
        }