Esempio n. 1
0
        public bool DeleteData(int id, out Library.DTO.Notification notification)
        {
            notification      = new Library.DTO.Notification();
            notification.Type = Library.DTO.NotificationType.Success;

            bool resultDelete = false;

            try
            {
                using (var context = CreateContext())
                {
                    SystemSetting systemSetting = context.SystemSetting.FirstOrDefault(o => o.SystemSettingID == id);

                    if (systemSetting == null)
                    {
                        notification.Type    = Library.DTO.NotificationType.Error;
                        notification.Message = "Cannot found System Setting data!";

                        return(resultDelete);
                    }

                    context.SystemSetting.Remove(systemSetting);
                    context.SaveChanges();

                    resultDelete = true;
                }
            }
            catch (Exception ex)
            {
                notification.Type    = Library.DTO.NotificationType.Error;
                notification.Message = ex.Message;

                if (ex.InnerException != null && !string.IsNullOrEmpty(ex.InnerException.Message))
                {
                    notification.DetailMessage.Add(ex.InnerException.Message);
                }
            }

            return(resultDelete);
        }
Esempio n. 2
0
        public bool UpdateData(int userId, int id, ref object dtoItem, out Library.DTO.Notification notification)
        {
            notification      = new Library.DTO.Notification();
            notification.Type = Library.DTO.NotificationType.Success;

            DTO.SystemSetting2 systemSettingDto = ((Newtonsoft.Json.Linq.JObject)dtoItem).ToObject <DTO.SystemSetting2>();
            bool resultUpdate = false;

            // Check setting key is null.
            if (string.IsNullOrEmpty(systemSettingDto.SettingKey.Trim()))
            {
                notification.Type    = Library.DTO.NotificationType.Error;
                notification.Message = "Please input Setting Key!";

                return(resultUpdate);
            }

            // Check season is null.
            if (string.IsNullOrEmpty(systemSettingDto.Season.Trim()))
            {
                notification.Type    = Library.DTO.NotificationType.Error;
                notification.Message = "Please select Season!";

                return(resultUpdate);
            }

            try
            {
                using (var context = CreateContext())
                {
                    SystemSetting systemSetting = null;

                    if (id < 0)
                    {
                        // Check setting key exist.
                        systemSetting = context.SystemSetting.FirstOrDefault(o => o.SettingKey == systemSettingDto.SettingKey && o.Season == systemSettingDto.Season);
                        if (systemSetting != null)
                        {
                            notification.Type    = Library.DTO.NotificationType.Error;
                            notification.Message = "System Setting already in database!";

                            return(resultUpdate);
                        }
                        else
                        {
                            systemSetting = new SystemSetting();
                        }

                        context.SystemSetting.Add(systemSetting);
                    }
                    else
                    {
                        systemSetting = context.SystemSetting.FirstOrDefault(o => o.SystemSettingID == id);

                        if (systemSetting == null)
                        {
                            notification.Type    = Library.DTO.NotificationType.Error;
                            notification.Message = "Cannot found data!";

                            return(resultUpdate);
                        }
                    }

                    converter.DTO2DB_UpdateData(systemSettingDto, ref systemSetting);

                    systemSetting.SettingKey   = systemSettingDto.SettingKey;
                    systemSetting.SettingValue = systemSettingDto.SettingValue;

                    context.SaveChanges();

                    dtoItem = converter.DB2DTO_SystemSetting(context.SystemSetting2Mng_SystemSetting_View.FirstOrDefault(o => o.SystemSettingID == systemSetting.SystemSettingID));

                    resultUpdate = true;
                }
            }
            catch (Exception ex)
            {
                notification.Type    = Library.DTO.NotificationType.Error;
                notification.Message = ex.Message;

                if (ex.InnerException != null && !string.IsNullOrEmpty(ex.InnerException.Message))
                {
                    notification.DetailMessage.Add(ex.InnerException.Message);
                }
            }

            return(resultUpdate);
        }
Esempio n. 3
0
 public void DTO2DB_UpdateData(DTO.SystemSetting2 dtoItem, ref SystemSetting dbItem)
 {
     AutoMapper.Mapper.Map <DTO.SystemSetting2, SystemSetting>(dtoItem, dbItem);
 }