public JsonResult SaveRecordAttendance(string record)
        {
            JavaScriptSerializer serializer = new JavaScriptSerializer();

            // serializer.Deserialize<At>

            // conver from string to object
            List <AttendanceDaily> ads = serializer.Deserialize <List <AttendanceDaily> >(record);


            bool   status  = false;
            string message = string.Empty;

            DateTime date = new DateTime(2021, 4, 11);
            //var monthID;

            // var today = DateTime.Today;
            //  var month = new DateTime(today.Year, today.Month, 1);
            var firstDayOfMonth = new DateTime(date.Year, date.Month, 1);
            var lastDayOfMonth  = firstDayOfMonth.AddMonths(1).AddDays(-1);

            if (date.Day == 1)
            {
                context.AttendanceMonthlies.Add(new AttendanceMonthly()
                {
                    FromDate = firstDayOfMonth, ToDate = lastDayOfMonth
                });
                context.SaveChanges();
            }


            var month = context.AttendanceMonthlies.FirstOrDefault(d => d.ToDate == lastDayOfMonth);

            foreach (var ad in ads)
            {
                ad.ID      = null;
                ad.Date    = date;
                ad.MonthID = (int)month.ID;
                context.AttendanceDailies.Add(ad);
            }
            try
            {
                context.SaveChanges();
                status = true;
            }
            catch (Exception ex)
            {
                status  = false;
                message = ex.Message;
            }

            return(Json(new
            {
                status = status,
                message = message
            }));
        }
Exemple #2
0
        public JsonResult SaveTag(string completeTagDetails, string completeTags)
        {
            JavaScriptSerializer serializer = new JavaScriptSerializer();

            // conver from string to object
            CompleteTag completeTag = serializer.Deserialize <CompleteTag>(completeTags);
            List <CompleteTagDetail> completeTagDetail = serializer.Deserialize <List <CompleteTagDetail> >(completeTagDetails);

            bool   status  = false;
            string message = string.Empty;



            try
            {
                completeTag.ID   = null;
                completeTag.Date = DateTime.Now;
                context.CompleteTags.Add(completeTag);

                foreach (var ctd in completeTagDetail)
                {
                    ctd.ID = null;
                    context.CompleteTagDetails.Add(ctd);
                }

                context.SaveChanges();

                status = true;
            }
            catch (Exception ex)
            {
                status  = false;
                message = ex.Message;
            }

            return(Json(new
            {
                status = status,
                message = message
            }));
        }