public OutputModel UpdateCatering([FromBody] tblT_Catering ctr)
        {
            OutputModel output = new OutputModel();

            try
            {
                var data = db_masakin.tblT_Catering.Where(p => p.MerchantID == ctr.MerchantID &&
                                                          p.LocalID == ctr.LocalID &&
                                                          p.CateringID == ctr.CateringID &&
                                                          p.isActive == 1).Select(p => p).FirstOrDefault();

                if (ctr.Day1MenuID != data.Day1MenuID && ctr.Day2MenuID != data.Day2MenuID && ctr.Day3MenuID != data.Day3MenuID && ctr.Day4MenuID != data.Day4MenuID && ctr.Day5MenuID != data.Day5MenuID)
                {
                    data.LocalID = data.CateringID;
                    data.Rate    = 0;
                }

                data.Day1MenuID   = ctr.Day1MenuID;
                data.Day2MenuID   = ctr.Day2MenuID;
                data.Day3MenuID   = ctr.Day3MenuID;
                data.Day4MenuID   = ctr.Day4MenuID;
                data.Day5MenuID   = ctr.Day5MenuID;
                data.Description  = ctr.Description;
                data.Name         = ctr.Name;
                data.Quantity     = ctr.Quantity;
                data.Price        = ctr.Price;
                data.isActive     = ctr.isActive;
                data.DateModified = DateTime.Now;

                db_masakin.SaveChanges();

                if (data.isRepeat == 1)
                {
                    GenerateCateringAfterGetAll((int)data.MerchantID);
                }

                output.status  = "success";
                output.message = null;
                output.data    = data;
            }
            catch (Exception ex)
            {
                output.status  = "error";
                output.message = ex.Message;
                output.data    = null;
            }
            return(output);
        }
        public OutputModel SubmitCatering([FromBody] tblT_Catering ctr)
        {
            OutputModel output = new OutputModel();

            try
            {
                var check = db_masakin.tblT_Catering.Where(p => p.MerchantID == ctr.MerchantID &&
                                                           p.DateFirst == ctr.DateFirst &&
                                                           p.isActive == 1).Select(p => p).FirstOrDefault();

                if (check == null)
                {
                    ctr.Rate      = 0;
                    ctr.isActive  = 1;
                    ctr.Sold      = 0;
                    ctr.Temporary = 0;
                    db_masakin.tblT_Catering.Add(ctr);
                    db_masakin.SaveChanges();

                    var data = db_masakin.tblT_Catering.Where(p => p.MerchantID == ctr.MerchantID &&
                                                              p.DateFirst == ctr.DateFirst &&
                                                              p.isActive == 1).Select(p => p).FirstOrDefault();
                    data.DateCreated  = DateTime.Now;
                    data.DateModified = DateTime.Now;
                    data.LocalID      = data.CateringID;
                    db_masakin.SaveChanges();

                    if (ctr.isRepeat == 1)
                    {
                        if (ctr.DateFirst == DateTime.Now.StartOfWeek(DayOfWeek.Monday).AddDays(7))
                        {
                            DateTime dt2   = data.DateFirst.Value.AddDays(7);
                            DateTime dt2L  = data.DateLast.Value.AddDays(7);
                            var      week2 = db_masakin.tblT_Catering.Where(P => P.MerchantID == data.MerchantID &&
                                                                            P.DateFirst == dt2 &&
                                                                            P.isActive == 1).FirstOrDefault();
                            if (week2 == null)
                            {
                                var ctr2 = data;
                                ctr2.DateCreated = DateTime.Now;
                                ctr2.DateFirst   = dt2;
                                ctr2.DateLast    = dt2L;
                                db_masakin.tblT_Catering.Add(ctr2);
                                db_masakin.SaveChanges();
                            }

                            DateTime dt3   = data.DateFirst.Value.AddDays(7);
                            DateTime dt3L  = data.DateLast.Value.AddDays(7);
                            var      week3 = db_masakin.tblT_Catering.Where(P => P.MerchantID == data.MerchantID &&
                                                                            P.DateFirst == dt3 &&
                                                                            P.isActive == 1).FirstOrDefault();
                            if (week3 == null)
                            {
                                var ctr3 = data;
                                ctr3.DateCreated = DateTime.Now;
                                ctr3.DateFirst   = dt3;
                                ctr3.DateLast    = dt3L;
                                db_masakin.tblT_Catering.Add(ctr3);
                                db_masakin.SaveChanges();
                            }
                        }
                        else if (ctr.DateFirst == DateTime.Now.StartOfWeek(DayOfWeek.Monday).AddDays(14))
                        {
                            DateTime dt3   = data.DateFirst.Value.AddDays(7);
                            DateTime dt3L  = data.DateLast.Value.AddDays(7);
                            var      week3 = db_masakin.tblT_Catering.Where(P => P.MerchantID == data.MerchantID &&
                                                                            P.DateFirst == dt3 &&
                                                                            P.isActive == 1).FirstOrDefault();
                            if (week3 == null)
                            {
                                var ctr3 = data;
                                ctr3.DateCreated = DateTime.Now;
                                ctr3.DateFirst   = dt3;
                                ctr3.DateLast    = dt3L;
                                db_masakin.tblT_Catering.Add(ctr3);
                                db_masakin.SaveChanges();
                            }
                        }
                    }

                    output.status  = "success";
                    output.message = null;
                    output.data    = null;
                }
                else
                {
                    output.status  = "failed";
                    output.message = "Katering untuk periode tersebut sudah tersedia.";
                    output.data    = null;
                }
            }
            catch (Exception ex)
            {
                output.status  = "error";
                output.message = ex.Message;
                output.data    = null;
            }
            return(output);
        }