Exemplo n.º 1
0
        public ActionResult DeleteConfirmed(int id)
        {
            EmployeeAttendence employeeAttendence = _dbContext.EmployeeAttendences.Find(id);

            _dbContext.EmployeeAttendences.Remove(employeeAttendence);
            _dbContext.SaveChanges();
            return(RedirectToAction("Index"));
        }
Exemplo n.º 2
0
 public ActionResult Edit([Bind(Include = "Id,InTime,OutTime,WorkHours,OverTimeHours,EmployeeId,EmployeeFullName,Status,AttendenceId")] EmployeeAttendence employeeAttendence)
 {
     if (ModelState.IsValid)
     {
         _dbContext.Entry(employeeAttendence).State = EntityState.Modified;
         _dbContext.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.AttendenceId = new SelectList(_dbContext.Attendences, "Id", "Id", employeeAttendence.AttendenceId);
     return(View(employeeAttendence));
 }
        public async Task <SaveEmployeeAttendenceResponse> UpdateAsync(int id, EmployeeAttendence employeeAttendence)
        {
            var existingEmployeeAttendence = await _employeeAttendenceRepository.FindByIdAsync(id);

            if (existingEmployeeAttendence == null)
            {
                return(new SaveEmployeeAttendenceResponse("Employee not found."));
            }

            ///Authorized By NiNiWinMay(Table Joining) 23.6.2019
            ///

            existingEmployeeAttendence.Attendences.date                           = employeeAttendence.Attendences.date;
            existingEmployeeAttendence.Attendences.start_time                     = employeeAttendence.Attendences.start_time;
            existingEmployeeAttendence.Attendences.end_time                       = employeeAttendence.Attendences.end_time;
            existingEmployeeAttendence.Attendences.attendenceType                 = employeeAttendence.Attendences.attendenceType;
            existingEmployeeAttendence.Attendences.remark                         = employeeAttendence?.Attendences?.remark;
            existingEmployeeAttendence.Attendences.Employees.employee_No          = employeeAttendence?.Attendences?.Employees.employee_No;
            existingEmployeeAttendence.Attendences.Employees.employee_Name        = employeeAttendence?.Attendences?.Employees.employee_Name;
            existingEmployeeAttendence.Attendences.Employees.email                = employeeAttendence?.Attendences?.Employees.email;
            existingEmployeeAttendence.Attendences.Employees.dob                  = employeeAttendence.Attendences.Employees.dob;
            existingEmployeeAttendence.Attendences.Employees.nrc                  = employeeAttendence?.Attendences?.Employees.nrc;
            existingEmployeeAttendence.Attendences.Employees.phone_no_work        = employeeAttendence?.Attendences?.Employees.phone_no_work;
            existingEmployeeAttendence.Attendences.Employees.phone_no_personal    = employeeAttendence?.Attendences?.Employees.phone_no_personal;
            existingEmployeeAttendence.Attendences.Employees.gender               = employeeAttendence?.Attendences?.Employees.gender;
            existingEmployeeAttendence.Attendences.Employees.marital_status       = employeeAttendence?.Attendences?.Employees.marital_status;
            existingEmployeeAttendence.Attendences.Employees.nationality          = employeeAttendence?.Attendences?.Employees.nationality;
            existingEmployeeAttendence.Attendences.Employees.religion             = employeeAttendence?.Attendences?.Employees.religion;
            existingEmployeeAttendence.Attendences.Employees.permanent_address    = employeeAttendence?.Attendences?.Employees.permanent_address;
            existingEmployeeAttendence.Attendences.Employees.education_background = employeeAttendence?.Attendences?.Employees.education_background;
            existingEmployeeAttendence.Attendences.Employees.joined_date          = employeeAttendence.Attendences.Employees.joined_date;
            existingEmployeeAttendence.Attendences.Employees.employee_state       = employeeAttendence?.Attendences?.Employees.employee_state;
            existingEmployeeAttendence.Attendences.Employees.Addresses.line_1     = employeeAttendence?.Attendences?.Employees.Addresses.line_1;
            existingEmployeeAttendence.Attendences.Employees.Addresses.line_2     = employeeAttendence?.Attendences?.Employees.Addresses.line_2;
            existingEmployeeAttendence.Attendences.Employees.Addresses.region     = employeeAttendence?.Attendences?.Employees.Addresses.region;
            existingEmployeeAttendence.Attendences.Employees.Addresses.country    = employeeAttendence?.Attendences?.Employees.Addresses.country;
            existingEmployeeAttendence.locations.lotitude                         = employeeAttendence.locations?.lotitude;
            existingEmployeeAttendence.locations.longitude                        = employeeAttendence.locations?.longitude;
            existingEmployeeAttendence.locations.remark                           = employeeAttendence.locations?.remark;


            try
            {
                _employeeAttendenceRepository.Update(existingEmployeeAttendence);
                await _unitOfWork.CompleteAsync();

                return(new SaveEmployeeAttendenceResponse(existingEmployeeAttendence));
            }
            catch (Exception ex)
            {
                // Do some logging stuff
                return(new SaveEmployeeAttendenceResponse($"An error occurred when saving the Department: {ex.Message}"));
            }
        }
Exemplo n.º 4
0
        public ActionResult Delete(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            EmployeeAttendence employeeAttendence = _dbContext.EmployeeAttendences.Find(id);

            if (employeeAttendence == null)
            {
                return(HttpNotFound());
            }
            return(View(employeeAttendence));
        }
Exemplo n.º 5
0
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            EmployeeAttendence employeeAttendence = _dbContext.EmployeeAttendences.Find(id);

            if (employeeAttendence == null)
            {
                return(HttpNotFound());
            }
            ViewBag.AttendenceId = new SelectList(_dbContext.Attendences, "Id", "Id", employeeAttendence.AttendenceId);
            return(View(employeeAttendence));
        }
        public async Task <SaveEmployeeAttendenceResponse> SaveAsync(EmployeeAttendence employeeAttendence)
        {
            try
            {
                await _employeeAttendenceRepository.AddAsync(employeeAttendence);

                await _unitOfWork.CompleteAsync();

                return(new SaveEmployeeAttendenceResponse(employeeAttendence));
            }
            catch (Exception ex)
            {
                // Do some logging stuff
                return(new SaveEmployeeAttendenceResponse($"An error occurred when saving the Department: {ex.Message}"));
            }
        }
Exemplo n.º 7
0
      public async Task <IActionResult> PostAsync([FromBody] EmployeeAttendence employeeAttendence)
      {           //get data form _departmentService by id
          if (!ModelState.IsValid)
          {
              return(BadRequest(ModelState.GetErrorMessages()));
          }
          //otherwise data save in database
          var result = await _employeeAttendenceService.SaveAsync(employeeAttendence);

          //if result is not success show error Message
          if (!result.Success)
          {
              return(BadRequest(result.Message));
          }

          return(Ok());
      }
Exemplo n.º 8
0
        public ActionResult Create(EmployeeAttendence employeeAttendence)
        {
            if (ModelState.IsValid)
            {
                var employees = _dbContext.Contacts.ToList();
                var viewModel = Mapper.Map <IEnumerable <EmployeeAttendence> >(employees);
                foreach (var employee in viewModel)
                {
                    _dbContext.EmployeeAttendences.Add(employeeAttendence);
                    _dbContext.SaveChanges();
                }

                return(RedirectToAction("Index"));
            }

            ViewBag.AttendenceId = new SelectList(_dbContext.Attendences, "Id", "Id", employeeAttendence.AttendenceId);
            return(View(employeeAttendence));
        }
Exemplo n.º 9
0
      public async Task <IActionResult> PutAsync(int id, [FromBody] EmployeeAttendence resource)
      {           // if Model is invalid show error message by using ModelState
          if (!ModelState.IsValid)
          {
              return(BadRequest(ModelState.GetErrorMessages()));
          }
          //get data form EmployeeAttendenceResource by id using AutoMapper
          //var employeeattendence=_mapper.Map<SaveEmployeeAttendenceResource,EmployeeAttendence>(resource);
          //update data by id
          var result = await _employeeAttendenceService.UpdateAsync(id, resource);

          //if update data is null

          if (result == null)
          {
              return(BadRequest(result));
          }
          //get result data from SaveDepartmentResource after update data using automapper
          var roleResource = _mapper.Map <EmployeeAttendence, EmployeeAttendenceResource>(result.EmployeeAttendence);

          //show data
          return(Ok(roleResource));
      }
 public void Update(EmployeeAttendence employeeAttendence)
 {
     _context.EmployeeAttendences.Update(employeeAttendence);
 }
 public void Remove(EmployeeAttendence employeeAttendence)
 {
     _context.EmployeeAttendences.Remove(employeeAttendence);
 }
 // add new Department Item
 public async Task AddAsync(EmployeeAttendence employeeAttendence)
 {
     await _context.EmployeeAttendences.AddAsync(employeeAttendence);
 }
Exemplo n.º 13
0
 /// <summary>
 /// Creates a success response.
 /// </summary>
 /// <param name="employee">Saved shipping.</param>
 /// <returns>Response.</returns>
 public SaveEmployeeAttendenceResponse(EmployeeAttendence employeeAttendence) : this(true, string.Empty, employeeAttendence)
 {
     EmployeeAttendence = employeeAttendence;
 }
Exemplo n.º 14
0
 private SaveEmployeeAttendenceResponse(bool success, string message, EmployeeAttendence employeeAttendence) : base(success, message)
 {
     EmployeeAttendence = employeeAttendence;
 }
Exemplo n.º 15
0
        public ActionResult Save(string employeeName, string inTimeVal, string outTimeVal, Guid AttendenceId, string attendenceTypeVal, DateTime date, Guid empidval, string command)
        {
            string messageToClient = string.Empty;

            if (ModelState.IsValid)
            {
                try
                {
                    if (command == "Submit")
                    {
                        int overTimeCalHr = 0;
                        int th            = 0;
                        EmployeeAttendence   employeeAttendence          = new EmployeeAttendence();
                        EmployeeSalary       employeeSalary              = new EmployeeSalary();
                        EmployeeSalaryDetail retriveEmployeeSalaryDetail = _dbContext.EmployeeSalaryDetails.Where(es => es.ContactId == empidval).FirstOrDefault();
                        if (inTimeVal == "")
                        {
                        }
                        else
                        {
                            DateTime i = Convert.ToDateTime(inTimeVal);
                            if (outTimeVal == "")
                            {
                            }
                            else
                            {
                                DateTime o = Convert.ToDateTime(outTimeVal);
                                //hour calculation
                                int inTime  = i.Hour;
                                int outTime = o.Hour;
                                if (inTime == outTime)
                                {
                                    inTime  = 0;
                                    outTime = 0;
                                }
                                if (inTime > 12)
                                {
                                    int newInTime = 24 - inTime;
                                    th = newInTime + outTime;
                                }
                                else
                                {
                                    th = outTime - inTime;
                                }

                                if (retriveEmployeeSalaryDetail != null)
                                {
                                    if (retriveEmployeeSalaryDetail.OverTimeCal != null)
                                    {
                                        DateTime overtimeCal = Convert.ToDateTime(retriveEmployeeSalaryDetail.OverTimeCal);
                                        overTimeCalHr = overtimeCal.Hour;
                                        //work hour and overtime hour Cal
                                        // retriving overtime and subtracting frm total hr
                                        if (th > overTimeCalHr)
                                        {
                                            int otHrcal = th - overTimeCalHr;
                                            employeeAttendence.WorkHours     = overTimeCalHr;
                                            employeeSalary.WorkHours         = overTimeCalHr;
                                            employeeAttendence.OverTimeHours = otHrcal;
                                            employeeSalary.OverTimeHours     = otHrcal;
                                        }
                                        else
                                        {
                                            employeeAttendence.WorkHours     = th;
                                            employeeSalary.WorkHours         = th;
                                            employeeAttendence.OverTimeHours = 0;
                                            employeeSalary.OverTimeHours     = 0;
                                        }
                                    }
                                }

                                //total Hours Cal
                                int im = i.Minute;
                                int om = o.Minute;
                                int t  = im + om;
                                if (im == om)
                                {
                                    employeeAttendence.TotalTime = Convert.ToString(th);
                                }
                                else if (im > om)
                                {
                                    employeeAttendence.TotalTime = Convert.ToString(th);
                                }
                                else if (t > 60)
                                {
                                    int totalhour = th + 1;
                                    int min       = t - 60;
                                    employeeAttendence.TotalTime = totalhour + " : " + min;
                                }
                                else
                                {
                                    employeeAttendence.TotalTime = th + " : " + t;
                                }
                            }
                        }


                        employeeAttendence.AttendenceId   = AttendenceId;
                        employeeAttendence.EmployeeId     = empidval;
                        employeeAttendence.FullName       = employeeName;
                        employeeAttendence.AttendenceType = attendenceTypeVal;
                        employeeAttendence.Date           = date;
                        employeeAttendence.InTime         = inTimeVal;
                        employeeAttendence.OutTime        = outTimeVal;
                        employeeAttendence.Status         = true;
                        _dbContext.EmployeeAttendences.Add(employeeAttendence);

                        //emp salary
                        Salary salary = _dbContext.Salary.Where(s => s.Date == date).FirstOrDefault();
                        employeeSalary.FullName            = employeeName;
                        employeeSalary.RatePerHour         = retriveEmployeeSalaryDetail.RatePerHour;
                        employeeSalary.RatePerHourOvertime = retriveEmployeeSalaryDetail.RatePerHourOvertime;
                        employeeSalary.Date     = date;
                        employeeSalary.SalaryId = salary.Id;
                        _dbContext.EmployeeSalaries.Add(employeeSalary);
                        _dbContext.SaveChanges();
                    }
                    else
                    {
                        int overTimeCalHr = 0;
                        int th            = 0;
                        EmployeeAttendence employeeAttendence = _dbContext.EmployeeAttendences.Where(ea => ea.AttendenceId == AttendenceId && ea.FullName == employeeName).FirstOrDefault();
                        Salary             salary             = _dbContext.Salary.Where(s => s.Date == date).FirstOrDefault();
                        EmployeeSalary     employeeSalary     = _dbContext.EmployeeSalaries.Where(es => es.SalaryId == salary.Id && es.FullName == employeeName).FirstOrDefault();
                        if (inTimeVal == "")
                        {
                        }
                        else
                        {
                            DateTime i = Convert.ToDateTime(inTimeVal);
                            if (outTimeVal == "")
                            {
                            }
                            else
                            {
                                DateTime o = Convert.ToDateTime(outTimeVal);
                                //hour calculation
                                int inTime  = i.Hour;
                                int outTime = o.Hour;
                                if (inTime == outTime)
                                {
                                    inTime  = 0;
                                    outTime = 0;
                                }
                                if (inTime > 12)
                                {
                                    int newInTime = 24 - inTime;
                                    th = newInTime + outTime;
                                }
                                else
                                {
                                    th = outTime - inTime;
                                }

                                EmployeeSalaryDetail retriveEmployeeSalaryDetail = _dbContext.EmployeeSalaryDetails.Where(es => es.ContactId == empidval).FirstOrDefault();
                                if (retriveEmployeeSalaryDetail != null)
                                {
                                    if (retriveEmployeeSalaryDetail.OverTimeCal != null)
                                    {
                                        DateTime overtimeCal = Convert.ToDateTime(retriveEmployeeSalaryDetail.OverTimeCal);
                                        overTimeCalHr = overtimeCal.Hour;
                                        //work hour and overtime hour Cal
                                        // retriving overtime and subtracting frm total hr
                                        if (th > overTimeCalHr)
                                        {
                                            int otHrcal = th - overTimeCalHr;
                                            employeeAttendence.WorkHours     = overTimeCalHr;
                                            employeeSalary.WorkHours         = overTimeCalHr;
                                            employeeAttendence.OverTimeHours = otHrcal;
                                            employeeSalary.OverTimeHours     = otHrcal;
                                        }
                                        else
                                        {
                                            employeeAttendence.WorkHours     = th;
                                            employeeSalary.WorkHours         = th;
                                            employeeAttendence.OverTimeHours = 0;
                                            employeeSalary.OverTimeHours     = 0;
                                        }
                                    }
                                }

                                //total Hours Cal
                                int im = i.Minute;
                                int om = o.Minute;
                                int t  = im + om;
                                if (im == om)
                                {
                                    employeeAttendence.TotalTime = Convert.ToString(th);
                                }
                                else if (im > om)
                                {
                                    employeeAttendence.TotalTime = Convert.ToString(th);
                                }
                                else if (t > 60)
                                {
                                    int totalhour = th + 1;
                                    int min       = t - 60;
                                    employeeAttendence.TotalTime = totalhour + " : " + min;
                                }
                                else
                                {
                                    employeeAttendence.TotalTime = th + " : " + t;
                                }

                                //emp salary
                                employeeSalary.FullName            = employeeName;
                                employeeSalary.RatePerHour         = retriveEmployeeSalaryDetail.RatePerHour;
                                employeeSalary.RatePerHourOvertime = retriveEmployeeSalaryDetail.RatePerHourOvertime;
                                employeeSalary.Date     = date;
                                employeeSalary.SalaryId = salary.Id;
                                _dbContext.Entry(employeeSalary).State = EntityState.Modified;
                                _dbContext.SaveChanges();
                            }
                        }

                        employeeAttendence.AttendenceId            = AttendenceId;
                        employeeAttendence.EmployeeId              = empidval;
                        employeeAttendence.FullName                = employeeName;
                        employeeAttendence.AttendenceType          = attendenceTypeVal;
                        employeeAttendence.InTime                  = inTimeVal;
                        employeeAttendence.OutTime                 = outTimeVal;
                        employeeAttendence.Status                  = true;
                        _dbContext.Entry(employeeAttendence).State = EntityState.Modified;
                    }
                    _dbContext.SaveChanges();
                    return(Json(new { success = true }));
                }
                catch (DbUpdateException dbex)
                {
                    // var error = new ModelStateException(dbex);
                    //  Log4NetHelper.Log(String.Format("Cannot Create Deparment {0} ", viewModel.Id), LogLevel.ERROR, "Department", viewModel.Id, User.Identity.Name, dbex);
                    var msg = new ModelStateException(dbex);
                    TempData["MessageToClient"] = msg;
                    messageToClient             = msg.ToString();
                }
                catch (Exception ex)
                {
                    // Log4NetHelper.Log(String.Format("Cannot Create Deparment {0} ", viewModel.Id), LogLevel.ERROR, "Department", viewModel.Id, User.Identity.Name, ex);
                    var msg = new ModelStateException(ex);
                    TempData["MessageToClient"] = msg;
                }
            }

            ViewBag.CompanyId = new SelectList(_dbContext.Companyies, "Id", "CompanyName");
            return(View());
        }