예제 #1
0
 public async Task AddNote(Note note)
 {
     if (IsDayExsts(note.Date_FK))
     {
         await _context.Notes.AddAsync(note);
     }
     else
     {
         DayNote dayNote = new DayNote {
             Date = note.Date_FK.Date
         };
         dayNote.Notes.Add(note);
         await _context.AddAsync(dayNote);
     }
     await _context.SaveChangesAsync();
 }
예제 #2
0
        public async Task <IActionResult> Edit(int id, NoteViewModel noteViewModel)
        {
            if (id != noteViewModel.ID)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    if (!_noteRepository.IsDayExsts(noteViewModel.Date_FK.Date))
                    {
                        DayNote dayNote = new DayNote();
                        dayNote.Date = noteViewModel.Date_FK;
                        _context.DayNotes.Add(dayNote);
                    }
// Get Unique name to store it in DB
                    string uniqName = string.Empty;
                    uniqName = await UploadImage(noteViewModel);

                    noteViewModel.PicPath = uniqName;

                    Note note = CopyPOCOFromVM(noteViewModel);

                    _context.Update(note);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!NoteExists(noteViewModel.ID))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(noteViewModel));
        }
예제 #3
0
        protected void btnExport3Day_Click(object sender, EventArgs e)
        {
            IList list;
            int   count = GetData(out list, false);

            if (count == 0)
            {
                ShowErrors(Resources.errorNoBookingSave);
                return;
            }
            DateTime date = DateTime.ParseExact(txtDate.Text, "dd/MM/yyyy", CultureInfo.InvariantCulture);

            IList <ExpenseService> expenseList       = new List <ExpenseService>();
            IList <ExpenseService> expenseListExport = new List <ExpenseService>();

            foreach (RepeaterItem rptItem in rptCruiseExpense.Items)
            {
                HiddenField hiddenId = (HiddenField)rptItem.FindControl("hiddenId");
                Cruise      cruise   = Module.CruiseGetById(Convert.ToInt32(hiddenId.Value));
                Expense     expense  = Module.ExpenseGetByDate(cruise, date);
                Module.SaveOrUpdate(expense);
                Repeater rptServices = (Repeater)rptItem.FindControl("rptServices");
                expenseList = rptServicesToIList(rptServices);

                if (String.IsNullOrEmpty(Request.QueryString["cruiseid"]))
                {
                    for (int i = 0; i < rptServicesToIList(rptServices).Count; i++)
                    {
                        expenseListExport.Add(rptServicesToIList(rptServices)[i]);
                    }
                }
                else
                {
                    expenseListExport = rptServicesToIList(rptServices);
                }
                foreach (ExpenseService service in expenseList)
                {
                    service.Expense = expense;
                    if (service.IsRemoved)
                    {
                        if (service.Id > 0)
                        {
                            expense.Services.Remove(service);
                        }
                    }
                    else
                    {
                        // Phải có tên hoặc giá thì mới lưu
                        if (!string.IsNullOrEmpty(service.Name) || service.Cost > 0 ||
                            service.Type.Id == SailsModule.GUIDE_COST)
                        {
                            Module.SaveOrUpdate(service);
                        }
                    }
                }

                Module.SaveOrUpdate(expense);
            }

            if (Cruise != null)
            {
                DayNote note = Module.DayNoteGetByDay(Cruise, date);

                if (!string.IsNullOrEmpty(note.Note) || note.Id > 0)
                {
                    Module.SaveOrUpdate(note);
                }
            }

            LoadService(date);

            if (Cruise != null)
            {
                BarRevenue bar = Module.BarRevenueGetByDate(Cruise, date);
                Module.SaveOrUpdate(bar);
            }

            string tplPath = Server.MapPath("/Modules/Sails/Admin/ExportTemplates/Lenhdieutour_dayboat.xls");

            if (String.IsNullOrEmpty(Request.QueryString["cruiseid"]))
            {
                TourCommand.Export2(list, count, expenseListExport, _date, BookingFormat, Response, tplPath, null);
            }
            else
            {
                var cruise = Module.GetObject <Cruise>(Convert.ToInt32(Request.QueryString["cruiseid"]));
                TourCommand.Export2(list, count, expenseListExport, _date, BookingFormat, Response, tplPath, cruise);
            }
        }