public void AddHoliday(AddHolidayViewModel model) { try { if (model != null) { MasterHoliday entity = new MasterHoliday(); entity.HoliTitle = model.HoliTitle; entity.HoliDate = model.HoliDate; entity.HoliDay = model.HoliDay; entity.HoliMonth = model.HoliMonth; entity.HoliYear = model.HoliYear; entity.Remarks = model.Remarks; entity.AddInfo = model.AddInfo; entity.IsDefault = Convert.ToByte(model.IsDefault); db.MasterHolidays.Add(entity); } else { throw new Exception("Holiday could not be blank!"); } } catch (Exception) { throw; } }
private ErrorInfo GetHolidayList(FileStream file, out List <MasterHoliday> HolidayList) { HolidayList = new List <MasterHoliday>(); try { IWorkbook workbook = WorkbookFactory.Create(file); var sheet = workbook.GetSheetAt(0); int lastRow = sheet.LastRowNum; for (int i = 1; i <= lastRow; i++) { var holidayrecord = new MasterHoliday(); IRow row = sheet.GetRow(i); ICell cell = row == null ? null : row.GetCell(0); int intyyyymm = cell == null ? 0 : (int)cell.NumericCellValue; if (intyyyymm != 0) { holidayrecord.GetudoYYYYMM = intyyyymm; ICell cell_date = row == null ? null : row.GetCell(1); string string_date = cell_date == null ? string.Empty : cell_date.DateCellValue.ToShortDateString(); DateTime date; DateTime.TryParse(string_date, out date); holidayrecord.Day = date; ICell cell_holidayname = row == null ? null : row.GetCell(2); string string_enddate = cell_holidayname == null ? string.Empty : cell_holidayname.StringCellValue; holidayrecord.HolidayName = string_enddate; HolidayList.Add(holidayrecord); } else { return(new ErrorInfo()); } } } catch (Exception ex) { var errorinfo = new ErrorInfo(); errorinfo.HasError = true; errorinfo.ErrorReason = ex.Message; } return(new ErrorInfo()); }