Ejemplo n.º 1
0
        public IActionResult Save(AddTimeSheet items, [FromQuery] string save)
        {
            //Module items = itemsData.Data;
            //var itemsObject = await request.Content.;
            //AddTimeSheet items = JsonConvert.DeserializeObject<AddTimeSheet>(request);
            try
            {
                Timesheetv2 timeSheet         = new Timesheetv2();
                var         existingEmployeee = db.Timesheetv2.FirstOrDefault(item => items.empId == item.EmpId);
                if (existingEmployeee == null)
                {
                    timeSheet.EmpId   = items.empId;
                    timeSheet.EmpName = items.empName;
                    db.Add(timeSheet);
                    db.SaveChanges();
                }
                foreach (TimeSheetData value in items.Data)
                {
                    Timesheetitemv2  timeSheetItem  = new Timesheetitemv2();
                    Timesheetentryv2 timeSheetEntry = new Timesheetentryv2();
                    timeSheetItem.Hours       = value.hours;
                    timeSheetItem.EmpId       = items.empId;
                    timeSheetItem.Status      = save;
                    timeSheetItem.Submittedto = value.submittedto;
                    timeSheetItem.ToDate      = items.toDate;
                    timeSheetItem.FromDate    = items.fromDate;
                    timeSheetItem.Date        = value.date;
                    db.Add(timeSheetItem);
                    db.SaveChanges();
                    int index = timeSheetItem.TimestampId;

                    timeSheetEntry.Customer    = value.customer;
                    timeSheetEntry.Company     = value.company;
                    timeSheetEntry.Task        = value.task;
                    timeSheetEntry.Project     = value.project;
                    timeSheetEntry.Timestampid = index;

                    db.Add(timeSheetEntry);
                    db.SaveChanges();
                }
                return(Ok(new { value = 200 }));
            }
            catch (Exception e)
            {
                Console.Write(e);
                var s = e;
                return(BadRequest(new { error = e }));
            }
        }
        public async Task <IActionResult> Create([Bind("EmployeeId,FullName,Gender,Department,Company")] Employee employee)
        {
            if (ModelState.IsValid)
            {
                _context.Add(employee);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(employee));
        }
        public async Task <IActionResult> Create([Bind("Id,Dep_LastName,Dep_FirstName,Relationship,EmployeeId")] Dependent dependent)
        {
            if (ModelState.IsValid)
            {
                _context.Add(dependent);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["EmployeeId"] = new SelectList(_context.employees, "EmployeeId", "EmployeeId", dependent.EmployeeId);
            return(View(dependent));
        }