Beispiel #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 IActionResult save([FromBody] AddTimeSheet items)
        {
            try
            {
                TimeSheet timeSheet = new TimeSheet();


                var existingEmployeee = db.TimeSheet.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)
                {
                    TimeSheetItem  timeSheetItem  = new TimeSheetItem();
                    TimeSheetEntry timeSheetEntry = new TimeSheetEntry();
                    timeSheetItem.Hours       = value.Hours;
                    timeSheetItem.Empid       = items.Empid;
                    timeSheetItem.Status      = "Drafted";
                    timeSheetItem.Submittedto = value.Submittedto;
                    timeSheetItem.To          = items.To;
                    timeSheetItem.From        = items.From;
                    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();
                }
            }
            catch (Exception e)
            {
                Console.Write(e);
            }
            return(Ok());
        }